-2
This code below makes the engine go forward and after 3 seconds go back repetitively, but I would like it to go forward by clicking the push button and then go back by clicking the push button, I’m cracking my skull on this and I see it’s simple but I can’t get out of this part
I’m using H Bridge L293D circuit
# define velmotor 3
# define m1a 4
# define m1b 5
# define tmp 3000
int vel=0;
void setup() {
pinMode(velmotor, OUTPUT);
pinMode(m1a, OUTPUT);
pinMode(m1b, OUTPUT);
digitalWrite(m1a,LOW);
digitalWrite(m1b,LOW);
analogWrite(velmotor,vel);
}
void loop() {
vel=255;
analogWrite(velmotor,vel);
digitalWrite(m1a,LOW);
digitalWrite(m1b,HIGH);
delay(tmp);
digitalWrite(m1a,LOW);
digitalWrite(m1b,LOW);
delay(500);
digitalWrite(m1a,HIGH);
digitalWrite(m1b,LOW);
delay(tmp);
digitalWrite(m1a,LOW);
digitalWrite(m1b,LOW);
delay(500);
}