differential-drive-robot.ino
Coordinated control of two motors for mobile robot navigation using differential speed.
Motors 1 and 2 are used as left and right wheels. SPEED mode ensures stable regulation. Adjust signs (+/-) according to the physical mounting of motors on the chassis.
differential-drive-robot.ino
#include <M5Stack_MotorDriverUnit.h>
M5Stack_MotorDriverUnit motorDriver;
void setup() {
M5.begin();
motorDriver.begin();
motorDriver.setMode(1, MODE_SPEED);
motorDriver.setMode(2, MODE_SPEED);
}
void loop() {
// Avancer en ligne droite
motorDriver.setSpeed(1, 40);
motorDriver.setSpeed(2, 40);
delay(2000);
// Tourner à droite (roue gauche avance, roue droite recule ou s'arrête)
motorDriver.setSpeed(1, 40);
motorDriver.setSpeed(2, -40);
delay(1000);
// Arrêt progressif
motorDriver.setSpeed(1, 0);
motorDriver.setSpeed(2, 0);
delay(1000);
}