lattepanda-sigma2-rp2350-ws2812b-rgb-10.ino
Script MicroPython que utiliza las bibliotecas 'machine' y 'neopixel' para controlar LEDs WS2812B conectados al encabezado GPIO del RP2350. Ideal para visualizar la carga de la CPU o alertas de red.
Conecte el pin DATA de una tira WS2812B a un GPIO libre del conector RP2350 (p.ej., GP15), VCC a 3.3V y GND a tierra. Si la tira de LED consume más de 500mA, aliméntela por separado para no dañar el RP2350. Suba este script al RP2350 mediante Thonny o puerto serie y ejecútelo. Consulte el esquema oficial de LattePanda para la asignación física exacta de los pines.
lattepanda-sigma2-rp2350-ws2812b-rgb-10.ino
from machine import Pin
import neopixel
import time
import math
# Configuration du hardware
# Sur LattePanda Sigma 2, le RP2350 expose des broches GPIO via un connecteur.
# Supposons que la broche physique connectée au DATA de la bande LED soit GP15 (à vérifier selon votre schéma câblage).
PIN_LED = 15
NUM_LEDS = 8 # Nombre de LEDs sur la bande
# Initialisation de la bande LED
np = neopixel.NeoPixel(Pin(PIN_LED), NUM_LEDS)
def set_color(r, g, b):
for i in range(NUM_LEDS):
np[i] = (r, g, b)
np.write()
time.sleep(0.1)
def rainbow_cycle(wait):
for j in range(255):
for i in range(NUM_LEDS):
pix_index = (i * 255 // NUM_LEDS + j) & 255
np[i] = colorwheel(pix_index)
np.write()
time.sleep(wait)
def colorwheel(pos):
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
print("Démarrage de la démo RGB sur RP2350...")
# Séquence de test
try:
# 1. Allumer tout en rouge
set_color(255, 0, 0)
time.sleep(0.5)
# 2. Allumer tout en vert
set_color(0, 255, 0)
time.sleep(0.5)
# 3. Allumer tout en bleu
set_color(0, 0, 255)
time.sleep(0.5)
# 4. Effet arc-en-ciel
rainbow_cycle(0.01)
# 5. Effet progressif (simulation de charge CPU)
for i in range(NUM_LEDS + 1):
np.clear()
for j in range(i):
# Vert pour faible charge, rouge pour haute
intensity = int(255 * (j / NUM_LEDS))
np[j] = (intensity, 255 - intensity, 0)
np.write()
time.sleep(0.1)
# Extinction propre
np.fill(0)
np.write()
print("Terminé.")
except KeyboardInterrupt:
np.fill(0)
np.write()
print("Interruption manuelle.")