rgb-led-status-indicator.ino

Unit 4-Encoder Motor Driver (DRV8837DSGR) · File : rgb-led-status-indicator.ino · Language : arduino · Use case : Utiliser la LED RGB WS2812C intégrée pour indiquer l'état du moteur (erreur ou fonctionnement).

Example of using the integrated RGB LED for visual feedback of the driver system status.

The WS2812C LED is often accessible via module registers or a dedicated GPIO. Check the specific documentation for your board revision for the exact LED GPIO address.

rgb-led-status-indicator.ino

#include <M5Stack_MotorDriverUnit.h>
#include <Adafruit_NeoPixel.h>

M5Stack_MotorDriverUnit motorDriver;

// La LED est souvent pilotée via I2C ou GPIO spécifique selon la version
// Exemple générique si la lib expose la LED
void setup() {
  M5.begin();
  motorDriver.begin();
  // Initialiser la LED (adresse interne ou GPIO 40 selon schéma M5Stack)
  // Note : Sur certaines versions, la LED est sur GPIO 40
  // Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 40, NEO_GRB + NEO_KHZ800);
  // strip.begin();
}

void loop() {
  // Simuler une erreur de moteur
  int status = motorDriver.getStatus(1);
  if (status != 0) {
    // Allumer en rouge (via registre LED ou lib)
    // motorDriver.setLEDColor(255, 0, 0); 
    Serial.println("Motor Error!");
  } else {
    // Allumer en vert
    // motorDriver.setLEDColor(0, 255, 0);
    Serial.println("Motor OK");
  }
  delay(500);
}

← Back to the board