HUE_END = 260 # Set up brightness minimum and maximum (between 0.0 and 1.0) BRIGHTNESS_MIN = 0.2 BRIGHTNESS_MAX = 0.7 # Set up speed (wait time between updates, in seconds.) SPEED = 0.3 # Pick *one* LED type by uncommenting the relevant line below: # APA102 / DotStar™ LEDs # led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK) # WS2812 / NeoPixel™ LEDs led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT) # Start updating the LED strip led_strip.start() # Light up all the leds random colours and brightnesses from the specified ranges... for i in range(NUM_LEDS): led_strip.set_hsv(i, randrange(HUE_START, HUE_END) / 360, 1.0, uniform(BRIGHTNESS_MIN, BRIGHTNESS_MAX)) while True: # ...and then update one random pixel at a time to keep things fresh and sparkly. # Comment out the lines below if you want static lights. led_strip.set_hsv(randrange(0, NUM_LEDS), randrange(HUE_START, HUE_END) / 360, 1.0,
This example uses the Plasma WS2812 LED library to drive a string of LEDs alongside the built-in RGB LED. You should wire your LEDs to VBUS/GND and connect the data pin to pin 27 (unused by Pico Wireless). Go to: https://<address>:<port>/set_led/<index> to set a single LED """ NUM_LEDS = 30 # Number of connected LEDs LED_PIN = 27 # LED data pin (27 is unused by Pico Wireless) LED_PIO = 0 # Hardware PIO (0 or 1) LED_SM = 0 # PIO State-Machine (0 to 3) r = 0 g = 0 b = 0 led_strip = plasma.WS2812(NUM_LEDS, LED_PIO, LED_SM, LED_PIN) # Edit your routes here # Nothing fancy is supported, just plain ol' URLs and GET/POST methods @ppwhttp.route("/", methods=["GET", "POST"]) def get_home(method, url, data): if method == "POST": global r, g, b r = int(data.get("r", 0)) g = int(data.get("g", 0)) b = int(data.get("b", 0)) ppwhttp.set_led(r, g, b) for i in range(NUM_LEDS): led_strip.set_rgb(i, r, g, b) print("Set LED to {} {} {}".format(r, g, b))