neopixel — WS2812 LED Strip
NeoPixels, also known as WS2812 LED strips, are full-color LED strings connected together. You can set their red, green, and blue values between 0 and 255. The neopixel module generates WS2812 control signals through precise timing control.
Constructors
- class NeoPixel(pin, n, bpp=3, timing=0, brightness=1.0)
pin: Output pin, see below for available pinsn: Number of LEDsbpp:3: Default 3-tuple RGB4: For LEDs with more than 3 colors, such as RGBW or RGBY pixels, uses 4-tuple
timing: Default is 0 for 400KHz rate; 1 for 800KHz ratebrightness: Brightness adjustment, range 0~1, default is 1.0
Attention
Available pins for NeoPixel on mPython Board: P5, P6, P7 (onboard RGB), P8, P9, P11, P13, P14, P15, P16, P19, P20.
Example:
from machine import Pin
import neopixel
pin = Pin(17, Pin.OUT)
np = neopixel.NeoPixel(pin, n=3,bpp=3,timing=1) #800khz
Methods
- NeoPixel.write()
Write data to the LEDs.
Example:
np[0] = (255, 255, 255) # Set the first LED pixel to white
np.write()
- NeoPixel.fill(rgb_buf)
Fill all LED pixels.
rgb_buf: RGB color
Example:
np.fill( (255, 255, 255) )
- NeoPixel.brightness(brightness)
Brightness adjustment, range 0~1.0