Making a DC motor switch directions, using a h-bridge and arduino

I’m working on a school project were i’ve build a tennis ball machine.
I want this machine to be able to switch directions, which is why i made my own h-bridge where i included 2x 3-pin screw terminals. Two of the pins is where the DC motor is connected. The other two pins is where the arduino is connected. And the last two pins is where i connect the power supply.
Now to the actual question.
I’m looking for a command where one of my pins can stay “HIGH” for 3 seconds and afterwards continue the loop. If you look at my code below, I need the described type of command replaced with the “delay”, since the delay only pauses the program, which is not what my intention is.
Excuse my english, it’s not my primary language, so I hope you’re able to understand my question :slight_smile:

#define left 9
#define right 10

void setup()
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);

void loop()
digitalWrite(left, LOW);
digitalWrite(right, HIGH);

The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.


That seems like what i'm looking for!
Thank you very much Robin2 :smiley: