m5stack-encoder-motor-led-status.ino
Control of the programmable RGB LED via I2C for visual feedback.
This example shows how to change the color of the integrated WS2812C LED. The LED is driven by the internal microcontroller, accessible via specific I2C registers (indicative addresses). This allows indicating system status without additional wiring. Check the datasheet for exact LED control registers.
m5stack-encoder-motor-led-status.ino
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
// La LED WS2812C est connectée à un GPIO interne du STM32G031
// Pour la contrôler via I2C, on utilise généralement un registre dédié
// ou on accède via la bibliothèque M5Stack qui abstrait cela.
#define I2C_ADDRESS 0x2F
#define REG_LED_R 0x10
#define REG_LED_G 0x11
#define REG_LED_B 0x12
void setup() {
Serial.begin(115200);
Wire.begin();
}
void loop() {
// Rouge : Moteur en marche
setLED(255, 0, 0);
delay(1000);
// Vert : Arrêt
setLED(0, 255, 0);
delay(1000);
// Bleu : Erreur ou Idle
setLED(0, 0, 255);
delay(1000);
}
void setLED(uint8_t r, uint8_t g, uint8_t b) {
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(REG_LED_R);
Wire.write(r);
Wire.write(g);
Wire.write(b);
Wire.endTransmission();
}