Hello ,
I'm using the following code to run a stepper motor. The motor works fine. However, I want to modify the code, so that the motor would rotate a specific distance and stop, rather than rotate continuously in a loop. I really do not have much idea about arduino coding. So could someone please help me..Thanks in advance!!
Here's the code I'm using
int Distance = 0;
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, HIGH);
delayMicroseconds(200);
digitalWrite(9, LOW);
delayMicroseconds(200);
Distance = Distance + 1;
if (Distance == 3600)
{
if (digitalRead(8 ) == LOW)
{
digitalWrite(8, HIGH);
}
else
{
digitalWrite(8, LOW);
}
Distance = 0;
delay(500);
}
}