neopixel_pulsation.py

Adafruit Feather nRF52840 Express · File : neopixel_pulsation.py · Language : Python · Use case : Faire pulsoter le NeoPixel embarqué

The Feather first hello: the NeoPixel soldered on board pulses in orange. board.NEOPIXEL is the dedicated pin CircuitPython defines for this exact board — no wiring, no resistor, current flows through the on-board regulator.

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 nRF52840 Express powered from its USB connector. The neopixel library ships in the Adafruit bundle.

Wiring

None. For an external NeoPixel strip: DATA to a free pin (say D5), VOUT to 5 V when USB-powered, common grounds.

How it works

neopixel.NeoPixel drives the WS2812 stream in hardware; the loop ramps the red component 0 to 255 in steps of 4 with 10 ms pauses — a ~1.3 s breath.

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

Change the pattern (rainbow, chaser), wire a N-pixel strip on D5, or bind the color to an I2C sensor for an ambient lamp.

neopixel_pulsation.py

# Pulsation du NeoPixel embarqué de la Feather nRF52840 Express.
# Bibliothèque : adafruit_neopixel (incluse dans la distribution).
import time
import board
import neopixel

# Un seul pixel, liaison NeoPixel du board (broche dédiée, déjà câblée)
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

while True:
    # Montée progressive orange (R > G), 0 -> 255
    for i in range(0, 256, 4):
        pixel[0] = (i, i // 4, 0)
        time.sleep(0.01)
    # Descente symétrique
    for i in range(255, -1, -4):
        pixel[0] = (i, i // 4, 0)
        time.sleep(0.01)

← Back to the board