#include <Stepper.h>
/*
Stepper Motor A4988 Driver Example
No code here - use the pushbutton to rotate a single step, and the switch to control the direction
*/
int ledState = 1;
int readPin = 3;
int buttonOld = 1;
int buttonNew;
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
Serial.begin(9600);
myStepper.setSpeed(60);
pinMode(readPin, INPUT);
}
void loop() {
buttonNew = digitalRead(readPin);
if (buttonOld == 1 && buttonNew == 0) {
if (ledState == 1) {
ledState = 0;
} else {
ledState = 1;
}
}
if (ledState == 1) {
myStepper.step(stepsPerRevolution);
} else {
myStepper.step(-stepsPerRevolution);
}
Serial.print(ledState);
Serial.println(buttonNew);
buttonOld = buttonNew;
}