Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);
char val;
int pos=0;
int x;
void setup() {
// myStepper.setSpeed(60);
Serial.begin(9600); //Start serial connection, 9600 baud
}
void loop() {
if(Serial.available() > 0){
Serial.println("Serial.available");
Serial.println(val);
val = Serial.read();
}
if( val == '1' ) //if diference is greater than 2 steps.
{
Serial.println("turn right");
myStepper.step(1); // move one step to the left.
delay(50);
//pos++;
Serial.println(x);
}
else if( val == '0')
{
Serial.println("turn left");
myStepper.step(-1); // move one step to the right.
delay(50);
//pos--;
Serial.println(x);
}
else if( val == '2')
{
Serial.println("stop");
myStepper.step(0); // move one step to stop
delay(50);
//pos--;
Serial.println(x);
}