#include <AccelStepper.h>
#define dirPin 8
#define stepPin 9
// Define button pins
#define buttonPinCW 2
#define buttonPinCCW 3
AccelStepper stepper(AccelStepper::DRIVER, stepPin, dirPin);
void setup() {
// put your setup code here, to run once:
stepper.setMaxSpeed(20); // Set maximum speed value for the stepper
stepper.setAcceleration(1); // Set acceleration value for the stepper
stepper.setCurrentPosition(0); // Set the current position to 0 steps
}
void loop() {
boolean CWActive = digitalRead(buttonPinCW);
boolean CCWActive = digitalRead(buttonPinCCW);
if(CWActive == true) {
//Serial.println("Going Clockwise");
//stepper.setCurrentPosition(0)
stepper.moveTo(50);
stepper.run();
}
else if (CCWActive == true) {
//Serial.println("Going Counter Clockwise");
//stepper.setCurrentPosition(0);
stepper.moveTo(-50);
stepper.run();
}
}