Use PWM to drive the DC motor to rotate forward and backward.
namespace {
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
GPIO_NUM_27,
GPIO_NUM_13
);
GPIO_NUM_4,
GPIO_NUM_2
);
GPIO_NUM_17,
GPIO_NUM_12
);
GPIO_NUM_15,
GPIO_NUM_14
);
#else
GPIO_NUM_27,
0,
GPIO_NUM_13,
1
);
GPIO_NUM_4,
2,
GPIO_NUM_2,
3
);
GPIO_NUM_17,
4,
GPIO_NUM_12,
5
);
GPIO_NUM_15,
6,
GPIO_NUM_14,
7
);
#endif
}
void setup() {
Serial.begin(115200);
printf("setting up\n");
g_motor_0.Init();
g_motor_1.Init();
g_motor_2.Init();
g_motor_3.Init();
printf("setup completed\n");
}
void loop() {
g_motor_0.RunPwmDuty(1023);
g_motor_1.RunPwmDuty(1023);
g_motor_2.RunPwmDuty(1023);
g_motor_3.RunPwmDuty(1023);
printf("forward\n");
delay(1000);
g_motor_0.RunPwmDuty(-1023);
g_motor_1.RunPwmDuty(-1023);
g_motor_2.RunPwmDuty(-1023);
g_motor_3.RunPwmDuty(-1023);
printf("backward\n");
delay(1000);
}
A two-channel PWM motor driver class.
String Version()
Get the version number string.