Hi,
I've been trying to adapt this AccelStepper example code to work with one button to control the back and forth movement of the stepper, meaning one press to go forward, one press brings it back......
I'm not sure and overwhelmed with all the ways it can be done.
Here's what I'm trying to work with.......
#include <AccelStepper.h>
AccelStepper stepper(1, 3, 4);
int st = 1;
int targ = 500;
void setup()
{
pinMode(2, INPUT);
stepper.setMaxSpeed(200.0);
stepper.setAcceleration(200.0);
}
void loop()
{
if (st == 0 && digitalRead(2) == LOW)
{
st = 1;
targ = -targ; stepper.moveTo(targ);
}
else if (stepper.distanceToGo() == 0)
st = 0;
}
}
stepper.run();
}
I'm confused counting the button presses, using Boolean ect.....
Any guidance would be appreciated.
I've been trying to adapt this AccelStepper example code to work with one button to control the back and forth movement of the stepper, meaning one press to go forward, one press brings it back......
I'm not sure and overwhelmed with all the ways it can be done.
Here's what I'm trying to work with.......
#include <AccelStepper.h>
AccelStepper stepper(1, 3, 4);
int st = 1;
int targ = 500;
void setup()
{
pinMode(2, INPUT);
stepper.setMaxSpeed(200.0);
stepper.setAcceleration(200.0);
}
void loop()
{
if (st == 0 && digitalRead(2) == LOW)
{
st = 1;
targ = -targ; stepper.moveTo(targ);
}
else if (stepper.distanceToGo() == 0)
st = 0;
}
}
stepper.run();
}
I'm confused counting the button presses, using Boolean ect.....
Any guidance would be appreciated.