neopixel.py
The 800 kHz WS2812 frame is generated by the MCU, the animation comes from Python: the addressable strip joins the PC's scripting world. Mood lighting drivable by camera or music.
Hardware required
A LattePanda 3 Delta (x86 Intel N5105, Windows 10/11 or Ubuntu) with its Arduino-compatible co-processor (ATmega32U4) wired to the two 50-pin headers. 12 WS2812 + external 5 V supply ≥ 1 A + 330-470 Ω resistor on data.
Wiring
Strip data through 470 Ω to D5, VDD to the external supply, ground common with the header. A 1000 µF cap on the strip supply is advised.
How it works
The library sends the color list to the PinPong firmware, which bit-bangs the NRZ frame on the timer. The PC paces the animation, the MCU holds the 1.25 µs per bit. Host side: pip install pinpong then python3. MCU side: the ATmega32U4 shows up as a COM port — program it with the Arduino IDE (« Arduino Leonardo » board).
Going further
Control by spectral analysis of the mic (music → light), or weather as a color gradient.
neopixel.py
#!/usr/bin/env python3
# 12 WS2812 sur D5 — PinPong pilote la trame, le MCU la genere.
from pinpong.board import Board, Pin
from pinpong.libs.dfrobot_neopixel import Neopixel
import time
Board().begin()
ruban = Neopixel(Pin.D5, 12)
COULEURS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0)]
print("Comete RGB (Ctrl-C pour sortir)")
try:
tete = 0
while True:
ruban.rainbow(0) # fond discret
for i in range(12):
r, g, b = COULEURS[(tete + i) % 4]
ruban.set_pixel(i, r // 4, g // 4, b // 4)
ruban.set_pixel(tete, 255, 255, 255) # tete blanche
ruban.show()
tete = (tete + 1) % 12
time.sleep(0.08)
except KeyboardInterrupt:
ruban.rainbow(0)
print("\nRuban eteint")