Go Down

Topic: l298p shield & serial control (Read 287 times) previous topic - next topic

monolith

Hi all,

I am pretty new to C and the arduino. I am looking to control two channels via the l298p motor shield on top of an arduino uno with atmega 328.

The chassis I'm using has four DC motors and I have the left two motors wired together, and the right respectively. I'm looking to code basic forward, backward, left or right functions.

Essentially, left or right would run the sided in opposite directions to turn my robot. forward and reverse would just be all ahead fordward or reverse.

So far I have forward, but how would I handle the other directions? Should I nest them in the same loop?

//Arduino PWM Speed Control?
int E1 = 6;
int M1 = 7;
int E2 = 5;
int M2 = 4;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
Serial.begin(9600);
while (! Serial);
Serial.println("Enter the Direction")
}
void loop()
{
if (serial.available()))
{
int forward = Serial.parseInt();
if (forward = F)
{
digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 100); //PWM Speed Control
analogWrite(E2, 100); //PWM Speed Control
delay(30);
}


Thanks in advance!

Rich

CrossRoads

Search my recent posts, I did just what you are looking for for someone else.
Needed a little tweaking to compile right, but it was very close.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up