I've done a fair amount of searching and have tried a bunch of different things but I can't seem to understand what's going on.
I want the stepper motor to run non-loop using a selector switch, have the stepper motor run for 20s and turn off while the switch is held down, and with the selector switch to another position, have the stepper motor turn back 20s and go forward 40. second
Do you have an example?
I've been thinking for 5 days please help
Many thanks for any help you guys can give.
int PUL=10;
int DIR=9;
int ENA=8;
int SW = 2;
void setup() {
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);
pinMode (SW, INPUT_PULLUP);
}
void loop() {
if (digitalRead(SW) == 0)
{
for (int i=0; i<6400; i++)
{
digitalWrite(DIR,HIGH);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
delay(200);
for (int i=0; i<6400; i++)
{
digitalWrite(DIR,LOW);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
delay(200);
}
Hello feeldog
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.