#include <Stepper.h>
const int start = 2;
const int direction = 3;
volatile bool IsSpinnig = false;
volatile bool IsClockwise = true;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 10, 11, 12, 13);
int TurnSide(){
if(IsClockwise){
return 1;
}
else if(!IsClockwise){
return -1;
}
return 0;
}
void setup() {
Serial.begin(9600);
myStepper.setSpeed(100);
pinMode(start, INPUT_PULLUP);
pinMode(direction, INPUT_PULLUP);
attachInterrupt(0, ChangeDirection, FALLING);
attachInterrupt(1, StartStop, FALLING);
}
void loop()
{
if (IsSpinnig)
{
myStepper.step(stepsPerRevolution / 100 * TurnSide());
}
}
void StartStop(){
IsSpinnig = !IsSpinnig;
}
void ChangeDirection(){
IsClockwise = !IsClockwise;
}