neopixel — WS2812/ NeoPixel LED 的控制

此模块为 WS2818 / NeoPixel LED 提供驱动程序。

注意

This module is only included by default on the ESP8266 and ESP32 ports. On STM32 / Pyboard, you can 下载模块 并将其拷贝到文件系统。

class NeoPixel

This class stores pixel data for a WS2812 LED strip connected to a pin. The application should set pixel data and then call NeoPixel.write() when it is ready to update the strip.

例如:

import neopixel
# 32 LED strip connected to X8.
p = machine.Pin.board.X8
n = neopixel.NeoPixel(p, 32)
# Draw a red gradient.
for i in range(32):
    n[i] = (i * 8, 0, 0)
# Update the strip.
n.write()
											

构造函数

class neopixel. NeoPixel ( pin , n , * , bpp = 3 , timing = 1 )

Construct an NeoPixel object. The parameters are:

  • pin 是 machine.Pin 实例。

  • n is the number of LEDs in the strip.

  • bpp is 3 for RGB LEDs, and 4 for RGBW LEDs.

  • timing is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz).

像素访问方法

NeoPixel. fill ( pixel )

Sets the value of all pixels to the specified pixel value (i.e. an RGB/RGBW tuple).

NeoPixel. __len__ ( )

返回条带 LED 数。

NeoPixel. __setitem__ ( index , val )

Set the pixel at index to the value, which is an RGB/RGBW tuple.

NeoPixel. __getitem__ ( index )

Returns the pixel at index as an RGB/RGBW tuple.

输出方法

NeoPixel. write ( )

将当前像素数据写入条带。