|
| 1 | +:mod:`neopixel` --- control of WS2812 / NeoPixel LEDs |
| 2 | +===================================================== |
| 3 | + |
| 4 | +.. module:: neopixel |
| 5 | + :synopsis: control of WS2812 / NeoPixel LEDs |
| 6 | + |
| 7 | +This module provides a driver for WS2818 / NeoPixel LEDs. |
| 8 | + |
| 9 | +.. note:: This module is only included by default on the ESP8266 and ESP32 |
| 10 | + ports. On STM32 / Pyboard, you can `download the module |
| 11 | + <https://github.com/micropython/micropython/blob/master/drivers/neopixel/neopixel.py>`_ |
| 12 | + and copy it to the filesystem. |
| 13 | + |
| 14 | +class NeoPixel |
| 15 | +-------------- |
| 16 | + |
| 17 | +This class stores pixel data for a WS2812 LED strip connected to a pin. The |
| 18 | +application should set pixel data and then call :meth:`NeoPixel.write` |
| 19 | +when it is ready to update the strip. |
| 20 | + |
| 21 | +For example:: |
| 22 | + |
| 23 | + import neopixel |
| 24 | + |
| 25 | + # 32 LED strip connected to X8. |
| 26 | + p = machine.Pin.board.X8 |
| 27 | + n = neopixel.NeoPixel(p, 32) |
| 28 | + |
| 29 | + # Draw a red gradient. |
| 30 | + for i in range(32): |
| 31 | + n[i] = (i * 8, 0, 0) |
| 32 | + |
| 33 | + # Update the strip. |
| 34 | + n.write() |
| 35 | + |
| 36 | +Constructors |
| 37 | +------------ |
| 38 | + |
| 39 | +.. class:: NeoPixel(pin, n, *, bpp=3, timing=1) |
| 40 | + |
| 41 | + Construct an NeoPixel object. The parameters are: |
| 42 | + |
| 43 | + - *pin* is a machine.Pin instance. |
| 44 | + - *n* is the number of LEDs in the strip. |
| 45 | + - *bpp* is 3 for RGB LEDs, and 4 for RGBW LEDs. |
| 46 | + - *timing* is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz). |
| 47 | + |
| 48 | +Pixel access methods |
| 49 | +-------------------- |
| 50 | + |
| 51 | +.. method:: NeoPixel.fill(pixel) |
| 52 | + |
| 53 | + Sets the value of all pixels to the specified *pixel* value (i.e. an |
| 54 | + RGB/RGBW tuple). |
| 55 | + |
| 56 | +.. method:: NeoPixel.__len__() |
| 57 | + |
| 58 | + Returns the number of LEDs in the strip. |
| 59 | + |
| 60 | +.. method:: NeoPixel.__setitem__(index, val) |
| 61 | + |
| 62 | + Set the pixel at *index* to the value, which is an RGB/RGBW tuple. |
| 63 | + |
| 64 | +.. method:: NeoPixel.__getitem__(index) |
| 65 | + |
| 66 | + Returns the pixel at *index* as an RGB/RGBW tuple. |
| 67 | + |
| 68 | +Output methods |
| 69 | +-------------- |
| 70 | + |
| 71 | +.. method:: NeoPixel.write() |
| 72 | + |
| 73 | + Writes the current pixel data to the strip. |
0 commit comments