# 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 LUMAR = 8 # Red Brightness LUMAG = 8 # Green Brightness LUMAB = 8 # Blue Brightness # Create the NeoPixel object np = neopixel.NeoPixel(Pin(LED_PIN), NUM_LEDS) print (np) # ------------------------------- # Helper Functions # ------------------------------- def clear(): """Turn all LEDs off.""" for i in range(NUM_LEDS): np[i] = (0, 0, 0) np.write() def fill(color): """Set every LED to the same colour.""" for i in range(NUM_LEDS): np[i] = color np.write() # ------------------------------- # Main Program # ------------------------------- while True: print ("Set every LED to Red") # Red fill((LUMAR, 0, 0)) time.sleep(1) print ("Set every LED to Green") # Green fill((0, LUMAG, 0)) time.sleep(1) print ("Set every LED to Blue") # Blue fill((0, 0, LUMAB)) time.sleep(1) print ("Set every LED to White") # White fill((LUMAR, LUMAG, LUMAB)) time.sleep(1) print ("Clear all LEDs") # Off clear() time.sleep(0.5)