Hi,
I having an issue with the sketch below, it works fine the first time but won't work again afterwards (unless you press reset). Basically what should happen is that when the switch D10 is pressed the sketch should rewind the motor until it hits a limit switch (D7) and then move it forward to its home position. But unfortunately after doing it the first time it justs sits there.
I have looked at D10 on the serial monitor and it is constantly reading 1's until D10 is pressed and then you get a single zero and no further zero's no matter how many times D10 is pressed.
Any help would be appreciated
Steve
#include <AccelStepper.h>
AccelStepper stepper1(1, 5, 4);
const int ActivationButton = 10;
const int limitButton = 7;
byte LBval;
byte buttonState;
void setup() {
Serial.begin(9600);
pinMode(ActivationButton, INPUT_PULLUP);
pinMode(limitButton, INPUT_PULLUP);
}
void loop () {
buttonState = digitalRead(ActivationButton);
Serial.println(buttonState);
if (buttonState == LOW)
{
stepper1.setMaxSpeed(800);
stepper1.setAcceleration(2500);
do
{
stepper1.setSpeed(800);
stepper1.runSpeed();
LBval = digitalRead(limitButton);
} while (LBval == HIGH);
do
{
stepper1.moveTo(-1);
stepper1.run();
} while (LBval == LOW);
}
}