i am brand new to arduino and was looking for a little help. i am looking to activate a motor once the button is pushed for 10 seconds and then have it stop. then the next time the button is pushed, it runs in reverse for ten seconds and stops. i need it to continue this cycle everytime the button is pushed. button push 1 = forward 10 seconds, button push 2 = reverse ten seconds, button push 3 = forward 10 seconds and so on... i believe i am very close to accomplishing this task however like i said i am new to all this and i could be miles away. any help would be appreciated. i am using a mega 2560 even though the picture shows an UNO. i dont think itll matter as long as i use the correct pins. link to tinkercad.com
int BUTTON = 9;
int DIRA = 3;
int DIRB = 4;
int FOR = true; //forward - reverse
int ENABLE = 5;
void setup() {
//---set pin direction
pinMode (ENABLE, OUTPUT);
pinMode (BUTTON, INPUT_PULLUP);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(BUTTON) == HIGH) {
digitalWrite(ENABLE, HIGH);
if (FOR == true) {
digitalWrite(DIRA,HIGH); //on forward
digitalWrite(DIRB,LOW);
delay(10000);
FOR = false;
digitalWrite(ENABLE,LOW); //stop
} else {
digitalWrite(DIRB,HIGH); //on reverse
digitalWrite(DIRA,LOW);
delay(1000);
FOR = true;
digitalWrite(ENABLE,LOW); //stop
}
}
}`
