#include <Stepper.h>
int cont = 0;
const int passos = 200;
Stepper motor(passos, 8, 9, 10, 11);
void setup()
{
pinMode(7, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
motor.setSpeed(60);
Serial.begin(9600);
}
void loop()
{
int hor = digitalRead(7);
int ant = digitalRead(6);
if (hor == LOW && ant == HIGH)
{
passos = 200;
cont = 1;
}
if (ant == LOW && hor == HIGH)
{
passos = 200;
cont = 0;
}
if (ant == LOW && hor == LOW)
{
passos = 0;
}
Serial.print("cont = ");
Serial.println(cont);
Serial.print("hor = ");
Serial.println(hor);
Serial.print("ant = ");
Serial.println(ant);
switch(cont)
{
case 0:
motor.step(passos);
delay(250);
break;
case 1:
motor.step(-passos);
delay(250);
break;
}
}