ws2812 - Neopixel LEDs

The ws2812 module controls LEDs of the WS2812 type. Just as the leds module, it exposes a function ws2812.set_all(), which works a similar fashion.

New in version 1.10.

ws2812.set_all(pin, colors)

Set multiple of the LEDs to RGB values.

Filling starts at the LED connected to the specified gpio pin.

Parameters
  • pin (int) – ID of the pin to use for sending the data.

  • colors – List of RGB triplets.

Example

import color, time, ws2812, gpio

gpio.set_mode(gpio.WRISTBAND_2, gpio.mode.OUTPUT)

i = 0
while True:
    col1 = color.from_hsv(i % 360, 1.0, 0.1)
    col2 = color.from_hsv((i + 20) % 360, 1.0, 0.1)
    col3 = color.from_hsv((i + 40) % 360, 1.0, 0.1)
    ws2812.set_all(gpio.WRISTBAND_2, [col1, col2, col3])
    i += 1
    time.sleep_ms(10)

New in version 1.10.