Ardunio L298 motor control

I’m sharing part of the code used in a sumo robot. Namely the functions used to control the directions of the motors. For each motor you need the enable pin for the respective bridge and the two logic pins.

int motor1enbl=30;
int motor1logic1=22;
int motor1logic2=24;

int motor2enbl=32;
int motor2logic1=26;
int motor2logic2=28;

The motor movement functions are named mxdiry where x is the motor( 1 or 2) and y is the direction (also 1 or 2, depends how you connected them).

void m1dir1()
{digitalWrite(motor1enbl,LOW);
digitalWrite(motor1logic1,HIGH);
digitalWrite(motor1logic2,LOW);
digitalWrite(motor1enbl,HIGH);
}

void m1dir2()
{digitalWrite(motor1enbl,LOW);
digitalWrite(motor1logic1,LOW);
digitalWrite(motor1logic2,HIGH);
digitalWrite(motor1enbl,HIGH);
}

void m2dir1()
{digitalWrite(motor2enbl,LOW);
digitalWrite(motor2logic1,HIGH);
digitalWrite(motor2logic2,LOW);
digitalWrite(motor2enbl,HIGH);
}

void m2dir2()
{digitalWrite(motor2enbl,LOW);
digitalWrite(motor2logic1,LOW);
digitalWrite(motor2logic2,HIGH);
digitalWrite(motor2enbl,HIGH);
}

And these are the actual movement functions used in the first version of the robot control software(may vary depending on how you wired everything up):

void m1stop() //stop motor 1
{digitalWrite(motor1enbl,LOW);
digitalWrite(motor1logic1,LOW);
digitalWrite(motor1logic2,LOW);
digitalWrite(motor1enbl,HIGH);}

 

void m2stop() //stop motor 2
{digitalWrite(motor2enbl,LOW);
digitalWrite(motor2logic1,LOW);
digitalWrite(motor2logic2,LOW);
digitalWrite(motor2enbl,HIGH);}

 

void otherway() //go back
{m1dir1();m2dir1();}
void forward() //go forward
{m1dir2();m2dir2();}
void tright() //turn right in place
{m1dir1();m2dir2();}
void tleft() //turn left in placce
{m1dir2();m2dir1();}
void lback() //arc turn left back
{m1dir1();m2stop();}
void lfront() //arc turn left front
{m1dir2();m2stop();}
void rback() //arc turn right back
{m2dir1();m1stop();}
void rfront() //arc turn right front
{m2dir2();m1stop();}
void stopm() // full stop
{m1stop();m2stop();}

Some rather outdated info on wiring can be found here.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)