neopixel_arcenciel.py
The universal ambient lamp: a phase-computed color wheel (no table) sweeps red-green-blue on the on-board NeoPixel. The visual base of any project — time, temperature or network state become a color.
Hardware
An Adafruit Feather nRF52840 Express (nRF52840 Cortex-M4F SoC, BLE 5 / 802.15.4) with on-board NeoPixel, red LED, 2 MB QSPI flash for the CircuitPython filesystem and a LiPo battery connector. Just the Feather. For a strip: set the pixel count to N and wire DATA to a 5 V-supplied pin with common ground.
Wiring
None for the on-board pixel. External strip: DATA→D5 through 330 Ω, VCC to VOUT (USB), common GND, 1000 µF cap across the strip supply.
How it works
The couleur function slices phase 0-1 into three segments and interpolates RGB channels; the loop advances phase by 0.01 every 30 ms — a full cycle in ~3 seconds.
Running it
CircuitPython (feather_nrf52840_express build) installed via the UF2 bootloader (double reset); edit code.py on the CIRCUITPY drive, console in Mu/Thonny.
Variants
Map a quantity (temperature → blue-red), stagger N pixels for a chaser, or sync the color with a BLE notification.
neopixel_arcenciel.py
# Arc-en-ciel tournant sur le NeoPixel embarqué.
# Roue des couleurs : (r, v, b) calculée par phase, sans table.
import time
import board
import neopixel
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.3)
def couleur(phase):
# phase 0.0 -> 1.0 : rouge -> vert -> bleu -> rouge
p = phase % 1.0
if p < 1/3:
return (int(765 * p * 3), int(765 * (1 - p * 3)), 0)
if p < 2/3:
q = (p - 1/3) * 3
return (0, int(765 * (1 - q)), int(765 * q))
r = (p - 2/3) * 3
return (int(765 * r), 0, int(765 * (1 - r)))
phase = 0.0
while True:
phase += 0.01
# neopixel attend 0-255 par canal : on divise 0-765 par 3
r, v, b = couleur(phase)
pixel[0] = (r // 3, v // 3, b // 3)
time.sleep(0.03)