My pro mini is writing values from a photocell to the serial monitor, reading correctly until exceeding the threshold, then stops and will not restart, even when the cell is returned to darkness. Assuming this is a software error. Would appreciate advise. Thanks.
#include <Stepper.h>
#define STEPS1 200
#define STOP 0
int rightSwitchPin =7;
int leftSwitchPin =8;
int sonarPin = A0;
int sonarValue = 0;
Stepper stepper1(STEPS1, 3,5,4,6);//bipolar
void setup()
{
stepper1.setSpeed(30);
Serial.begin(9600);
}
void loop()
{
sonarValue = analogRead (sonarPin);
// Serial.println (sonarValue);
delay(500);
if (sonarValue >900)
{
Serial.println (sonarValue);
while (digitalRead(rightSwitchPin) == LOW) //keep going until limit switch reached
{
stepper1.step(-1); //move right
}
while (digitalRead(leftSwitchPin) == LOW) //keep going until limit switch reached
{
stepper1.step(1); //move left
}
}
else
{
stepper1.step (STOP);
}
}