H-Bridge Sketch short circuit

Hi! What do you guys do in order not to short circuit h-bridge when programming something like this.
In my sketch below, there's no problem from moveForward to reverse, but reverse to forward, there's a point where motor1a and motor1b are HIGH. I also have problems with left, right.....

if I put motorstop in middle it would keep stopping??

motor1a and motor1b is One motor(if it's not obvious :))

 void moveForward() {
    digitalWrite(motor1a, HIGH); //
    digitalWrite(motor1b, LOW);
    analogWrite(mySpeed1, 150); // 0-255 Speed.
    
    digitalWrite(motor2a, HIGH);
    digitalWrite(motor2b, LOW);
    analogWrite(mySpeed2, 150); // 0-255 Speed.

}

void reverse() {
     digitalWrite(motor1a, LOW);
    digitalWrite(motor1b, HIGH);
    analogWrite(mySpeed1,180); // 0-255 Speed.
    
    digitalWrite(motor2a, LOW);
    digitalWrite(motor2b, HIGH);
    analogWrite(mySpeed2,180); // 0-255 Speed.
/code]

Any function that controls the direction should set both pins LOW first, then set the appropriate pin HIGH.

PaulS:
Any function that controls the direction should set both pins LOW first, then set the appropriate pin HIGH.

Yes, but would it make the motor keeps stopping, like stop forward stop forward?

Yes, but would it make the motor keeps stopping, like stop forward stop forward?

Only if you call the function more than once. You don't keep shifting your car into drive, do you? Why would you be doing that to your robot?

The functions should be doing nothing more than shifting the transmission. Separate functions should handle speed, just like your car. Your gas pedal is not connected to your transmission.

PaulS:
Only if you call the function more than once. You don't keep shifting your car into drive, do you? Why would you be doing that to your robot?

The functions should be doing nothing more than shifting the transmission. Separate functions should handle speed, just like your car. Your gas pedal is not connected to your transmission.

That's my problem I can't make it not to call stop function more than once. I added a stop in my sketch, but i
think this will keep stopping and going. What's the right way of doing this?Thanks for the replies. btw. this is for object following robot.

void moveForward() {

   digitalWrite(motor1a, LOW);
  digitalWrite(motor1b, LOW);
  digitalWrite(motor2a, LOW);
 digitalWrite(motor2b, LOW);

    digitalWrite(motor1a, HIGH); //
    digitalWrite(motor1b, LOW);
    analogWrite(mySpeed1, 150); // 0-255 Speed.
    
    digitalWrite(motor2a, HIGH);
    digitalWrite(motor2b, LOW);
    analogWrite(mySpeed2, 150); // 0-255 Speed.

}

void reverse() {

digitalWrite(motor1a, LOW);
digitalWrite(motor1b, LOW);
digitalWrite(motor2a, LOW);
digitalWrite(motor2b, LOW);
 
     digitalWrite(motor1a, LOW);
    digitalWrite(motor1b, HIGH);
    analogWrite(mySpeed1,180); // 0-255 Speed.
    
    digitalWrite(motor2a, LOW);
    digitalWrite(motor2b, HIGH);
    analogWrite(mySpeed2,180); // 0-255 Speed.
/code]
/code]

That's my problem I can't make it not to call stop function more than once.

Why can't you?

What's the right way of doing this?

Take your snippets to http://snippets-r-us.com where some fine folks will help you.

digitalWrite(motor1a, LOW);
digitalWrite(motor1b, LOW);
digitalWrite(motor2a, LOW);
digitalWrite(motor2b, LOW);
 
     digitalWrite(motor1a, LOW);

Just in case it didn't take the first time? Maybe you need three or four more calls.

PaulS:
Why can't you?
Take your snippets to http://snippets-r-us.com where some fine folks will help you.

digitalWrite(motor1a, LOW);

digitalWrite(motor1b, LOW);
digitalWrite(motor2a, LOW);
digitalWrite(motor2b, LOW);

digitalWrite(motor1a, LOW);



Just in case it didn't take the first time? Maybe you need three or four more calls.

PaulS:
Why can't you?
Take your snippets to http://snippets-r-us.com where some fine folks will help you.

digitalWrite(motor1a, LOW);

digitalWrite(motor1b, LOW);
digitalWrite(motor2a, LOW);
digitalWrite(motor2b, LOW);

digitalWrite(motor1a, LOW);



Just in case it didn't take the first time? Maybe you need three or four more calls.

What do you mean just in case it didnt take the 1st time, i only wrote it once, thats 4 different pins. Im just thinking itll loop while moving forward.

Im sorry, im not going to ask this stupid questions if i already know what to do lol.

What do you mean just in case it didnt take the 1st time, i only wrote it once, thats 4 different pins. Im just thinking itll loop while moving forward.

How many times in those 6 lines do you set motor1a's state? What do you set it to each time?

How many times do you NEED to set it?

Im just thinking itll loop while moving forward.

Nothing in that code loops. If looping happens, it is in some part of your code that you are keeping to yourself. You can't expect us to help you with code that you are not willing to share.