Alfred/tempo/dona/LED/led_automone.py
2025-11-11 13:38:25 +01:00

35 lines
895 B
Python

from apa102 import APA102
import time
# Initialiser la LED APA102 (1 LED sur le ReSpeaker Mic Hat)
num_leds = 12
led = APA102(num_led=num_leds)
def set_color(r, g, b):
for i in range(num_leds):
led.set_pixel(i, r, g, b)
led.show()
try:
while True:
choix = input("Choisissez une couleur (R pour Rouge, V pour Vert, B pour Bleu, Q pour Quitter) : ").upper()
if choix == 'R':
set_color(255, 0, 0)
elif choix == 'V':
set_color(0, 255, 0)
elif choix == 'B':
set_color(0, 0, 255)
elif choix == 'Q':
print("Extinction des LED...")
set_color(0, 0, 0)
break
else:
print("Entrée invalide. Veuillez choisir R, V, B ou Q.")
except KeyboardInterrupt:
pass
finally:
# Éteindre toutes les LED à la fin
set_color(0, 0, 0)
led.cleanup()