neopixel - NeoPixel strip driver

  • Author(s): Damien P. George, Scott Shawcroft, Carter Nelson, Rose Hooper
neopixel.GRB = 'GRB'

Green Red Blue

neopixel.GRBW = 'GRBW'

Green Red Blue White

class neopixel.NeoPixel(pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None)[source]

A sequence of neopixels.

Parameters:
  • pin (Pin) – The pin to output neopixel data on.
  • n (int) – The number of neopixels in the chain
  • bpp (int) – Bytes per pixel. 3 for RGB and 4 for RGBW pixels.
  • brightness (float) – Brightness of the pixels between 0.0 and 1.0 where 1.0 is full brightness
  • auto_write (bool) – True if the neopixels should immediately change when set. If False, show must be called explicitly.
  • pixel_order (str) – Set the pixel color channel order. GRBW is set by default.

Example for Circuit Playground Express:

import neopixel
from board import *

RED = 0x100000 # (0x10, 0, 0) also works

pixels = neopixel.NeoPixel(NEOPIXEL, 10)
for i in range(len(pixels)):
    pixels[i] = RED

Example for Circuit Playground Express setting every other pixel red using a slice:

import neopixel
from board import *
import time

RED = 0x100000 # (0x10, 0, 0) also works

# Using ``with`` ensures pixels are cleared after we're done.
with neopixel.NeoPixel(NEOPIXEL, 10) as pixels:
    pixels[::2] = [RED] * (len(pixels) // 2)
    time.sleep(2)
show()

Shows the new colors on the pixels themselves if they haven’t already been autowritten.

The colors may or may not be showing after this function returns because it may be done asynchronously.

fill(color)

Colors all pixels the given *color*.

brightness

Overall brightness of the pixel (0 to 1.0)

deinit()[source]

Blank out the NeoPixels and release the pin.

n

The number of neopixels in the chain (read-only)

write()[source]

Use show instead. It matches Micro:Bit and Arduino APIs.

neopixel.RGB = 'RGB'

Red Green Blue

neopixel.RGBW = 'RGBW'

Red Green Blue White