So I have an ESP32 connected with an H-Bridge and I'm trying to control a car
like this one:
My circuit is the bellow.
and I'm trying to change it with the bellow code. Going forward with a delay of 10seconds and then backward. The result is that it's only going forward without changing direction. I'm stuck with this for the past day. I would be really grateful if someone could give a tip here.
void setup()
{
// initialize digital pin 8 as an output.
Serial.begin(9600);
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(enB, OUTPUT);
// pinMode(dpin, OUTPUT);
}
void loop()
{
RightSpd = LeftSpd = 255
move (RightSpd, LeftSpd, HIGH, LOW, HIGH, LOW);
delay(10000);
move (RightSpd, LeftSpd, HIGH, LOW, LOW, HIGH);}
}
void move (int RightSpd, int LeftSpd, uint8_t val1, uint8_t val2, uint8_t val3, uint8_t val4)
{
analogWrite(enA, RightSpd);
analogWrite(enB, LeftSpd);
digitalWrite(in1,val1);
digitalWrite(in2,val2);
digitalWrite(in3,val3);
digitalWrite(in4,val4);
}