rgb_status_indicator.py
Control of the integrated RGB LED to provide visual feedback on operating status and errors.
Writes color values to the WS2812C LED registers. The code includes reading the status register to detect current errors (INA199A) and lighting the LED red. Register addresses (0x30-0x32, 0x40) are typical examples for this type of driver.
rgb_status_indicator.py
import time
from m5stack import i2c
ADDR = 0x2F
bus = i2c.I2C(1)
def set_rgb(r, g, b):
# La LED WS2812C est souvent pilotée via un registre dédié ou une commande spécifique
# Ici, on suppose une écriture directe dans les registres de couleur (0x30, 0x31, 0x32)
bus.writeto_mem(ADDR, 0x30, bytes([r]))
bus.writeto_mem(ADDR, 0x31, bytes([g]))
bus.writeto_mem(ADDR, 0x32, bytes([b]))
# État: Moteur actif
set_rgb(0, 255, 0) # Vert
print("Moteur actif")
time.sleep(2)
# État: Moteur arrêté
set_rgb(0, 0, 255) # Bleu
print("Moteur arrêté")
time.sleep(2)
# État: Erreur de courant (simulation)
# Vérifier le registre de statut (ex: 0x40) pour les flags d'erreur
status = bus.readfrom_mem(ADDR, 0x40, 1)[0]
if status & 0x01: # Bit d'erreur de courant
set_rgb(255, 0, 0) # Rouge
print("Erreur de courant détectée")