Yes, I didnt explain
Yes, I didnt explain correctly. VCC2 is hooked up to the power source that the h bridge is running off of. the motors are connected to the outputs on the chip. Sorry about that.
Now, about the PWM outputs…
the wires that go to the inputs on the h bridge are connected to 4,5,6,7 on my arduino… only two of those are PWM. I never really understood what PWM was for… Let me post the code i am using as well… It isn’t pretty, but i’m still new to coding…
#define leftDir1 7 // Left motor direction 1, to AIn1.
#define leftDir2 6 // Left motor direction 2, to AIn2.
#define rightDir1 5 // Right motor direction 1, to BIn1.
#define rightDir2 4 // Right motor direction 2, to BIn2.
void setup()
{
pinMode(leftDir1, OUTPUT); // Set motor direction pins as outputs.
pinMode(leftDir2, OUTPUT);
pinMode(rightDir1, OUTPUT);
pinMode(rightDir2, OUTPUT);
}
void loop()
{
drive_forward();
delay(8000);
motor_stop();
delay(2000);
turn_left();
delay(5000);
motor_stop();
delay(2000);
drive_forward();
delay(6000);
motor_stop();
delay(2000);
turn_left();
delay(5000);
motor_stop();
delay(2000);
drive_forward();
delay(8000);
motor_stop();
delay(2000);
turn_left();
delay(5000);
motor_stop();
delay(2000);
drive_forward();
delay(6000);
motor_stop();
delay(2000);
turn_left();
delay(4000);
}
// motor movements
void motor_stop(){
digitalWrite(leftDir1, HIGH);
digitalWrite(leftDir2, HIGH);
digitalWrite(rightDir1, HIGH);
digitalWrite(rightDir2, HIGH);
}
void drive_forward(){
digitalWrite(leftDir1, LOW);
digitalWrite(leftDir2, HIGH);
digitalWrite(rightDir1, HIGH);
digitalWrite(rightDir2, LOW);
}
void turn_left(){
digitalWrite(leftDir1, HIGH);
digitalWrite(leftDir2, LOW);
digitalWrite(rightDir1, HIGH);
digitalWrite(rightDir2, LOW);
}
void turn_right(){
digitalWrite(leftDir1, LOW);
digitalWrite(leftDir2, HIGH);
digitalWrite(rightDir1, LOW);
digitalWrite(rightDir2, HIGH);
}