#include <Stepper.h>
const int PIN_BUTTON_START = 3;
const int PIN_BUTTON_REVERSE = 2;
const int NUMBER_STEPS = 200;
long motorSpeed = 8;
bool startStop = false;
bool reverse = false;
long timeOutS = 0;
long timeOutR = 0;
long pause = 10;
Stepper myStepper(NUMBER_STEPS, 8, 9, 10, 11);
void setup() {
myStepper.setSpeed(motorSpeed);
pinMode(PIN_BUTTON_START, INPUT_PULLUP);
pinMode(PIN_BUTTON_REVERSE, INPUT_PULLUP);
attachInterrupt(0, myReverse, RISING);
attachInterrupt(1, myStartStop, RISING);
}
void myReverse() {
detachInterrupt(0);
reverse = !reverse;
timeOutR = 0;
}
void myStartStop() {
detachInterrupt(1);
startStop = !startStop;
timeOutS = 0;
}
void loop() {
if (startStop) {
if (reverse) {
myStepper.step(NUMBER_STEPS * -1 / 100 );
}
else {
myStepper.step(NUMBER_STEPS / 100);
}
}
if (timeOutR == pause) {
attachInterrupt(0, myReverse, RISING);
}
else {
timeOutR++;
}
if (timeOutS == pause) {
attachInterrupt(1, myStartStop, RISING);
}
else {
timeOutS++;
}
}