Outils pour utilisateurs

Outils du site


programme_pour_piloter_le_motor_shield_sur_arduino_rev4

Ceci est une ancienne révision du document !


  Ce programme pilote le moteur au travers de liaison série F:avancer, B; reculer, L: tourner à gauche,
  R: tourner à droite, S: stopper. A vous de faire évoluer ce programme.

motor1.zip

void setup() {
  init_moteurs();
  Serial.begin(115200);
  Serial.println("Motor Control Ready. Enter F, B, L, R, S.");
}
 
void loop() {
  // Check if there is data available on the serial input
  if (Serial.available() > 0) {
    char command = Serial.read(); // Read the incoming command
    command = toupper(command);  // Ensure command is uppercase
 
    switch (command) {
      case 'F':
        // Move forward
        avancer(150);
        Serial.println("Moving Forward");
        break;
 
      case 'B':
        // Move backward
        reculer(150);
        Serial.println("Moving Backward");
        break;
 
      case 'L':
        // Turn left (stop one motor, run the other)
        gauche(150);
        Serial.println("Turning Left");
        break;
 
      case 'R':
        // Turn right (stop one motor, run the other)
        droite(150);
        Serial.println("Turning Right");
        break;
 
      case 'S':
        // Stop all motors
        stopMotors();
        Serial.println("Stopping Motors");
        break;
 
      default:
        // Handle invalid commands
        Serial.println("Invalid Command. Use F, B, L, R, S.");
        break;
    }
  }
}
programme_pour_piloter_le_motor_shield_sur_arduino_rev4.1737649993.txt.gz · Dernière modification : 2025/01/23 16:33 de mistert