# WS2812 / NeoPixel Example # Raspberry Pi Pico + MicroPython # # Controls a strip of 12 LEDs connected to GP0. from machine import Pin import neopixel import time # ------------------------------- # Configuration # ------------------------------- LED_PIN = 8 # GPIO connected to DIN NUM_LEDS = 12 # Number of LEDs, 0-11 is used, not 1-12 # Create the NeoPixel object np = neopixel.NeoPixel(Pin(LED_PIN), NUM_LEDS) # ------------------------------- # Helper Functions # ------------------------------- def clear(): """Turn all LEDs off.""" for i in range(NUM_LEDS): np[i] = (0, 0, 0) np.write() def chase(color, delay=1): """Move one LED along the strip.""" clear() for i in range(NUM_LEDS): clear() np[i] = color np.write() time.sleep(delay) # ------------------------------- # Main Program # ------------------------------- while True: # Chase effect chase((255, 0, 0), 0.08) chase((0, 255, 0), 0.08) chase((0, 0, 255), 0.08)