ws2812.rst 937 Bytes
Newer Older
danb's avatar
danb committed
1 2 3 4 5 6
.. py:module:: ws2812

``ws2812`` - Neopixel LEDs
==========================
The ``ws2812`` module controls LEDs of the WS2812 type. Just as the ``leds`` module, it exposes a function :py:func:`ws2812.set_all`, which works a similar fashion.

Rahix's avatar
Rahix committed
7 8
.. versionadded:: 1.10

danb's avatar
danb committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
.. py:function:: set_all(pin, colors)

   Set multiple of the LEDs to RGB values.

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

   :param int pin: ID of the pin to use for sending the data.
   :param colors: List of RGB triplets.

   **Example**

   .. code-block:: python

      import color, utime, ws2812, gpio

      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
          utime.sleep_ms(10)

Rahix's avatar
Rahix committed
33
   .. versionadded:: 1.10