#include <AccelStepper.h>
#include <Bounce2.h>
AccelStepper myStepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
#define NUM_BUTTONS 1
const int buttonPin[NUM_BUTTONS] = {A0};
Bounce2::Button button[NUM_BUTTONS] = {Bounce2::Button()};
void setup()
{
Serial.begin(9600);
for (byte i = 0; i < NUM_BUTTONS; i++)
{
button[i].attach(buttonPin[i], INPUT_PULLUP);
button[i].setPressedState(LOW);
button[i].interval(5);
}
}
myStepper.setMaxSpeed(1000);
myStepper.setAcceleration(50);
myStepper.setSpeed(100);
{
void loop()
{
int debouncedState[NUM_BUTTONS];
for (byte i = 0; i < NUM_BUTTONS; i++)
{
button[i].update();
debouncedState[i] = button[i].read();
if ((debouncedState[0] == LOW) && (button[0].currentDuration() > 200))
{
myStepper.move(-10000);
myStepper.run();
delay(5);
}
else if ((debouncedState[1] == LOW) && (button[1].currentDuration() > 200))
{
myStepper.move(10000);
myStepper.run();
delay(5);
}
}
}