#include <AccelStepper.h> //AccelStepper library
AccelStepper stepper(1, 9, 8);// pulses Digital 9 (CLK); Direction Digital 8 (CCW)
const int button1Pin = 2; // the number of the pushbutton pin
const int button2Pin = 3; // the number of the pushbutton pin
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status
void setup()
{
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
}
void loop()
{
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
stepper.setMaxSpeed(200);
stepper.setAcceleration(10);
if (button1State == HIGH) {
stepper.stop();
stepper.moveTo(200);
stepper.runToPosition();
delay(1000);
}
if (button2State == HIGH) {
stepper.stop();
stepper.moveTo(0);
stepper.runToPosition();
delay(1000);
}
}