MojoScale Studio Docs
API Reference

neopixel

Addressable RGB/RGBW LED strip module.

Studio Docs Sensors & I/O

import neopixel

The neopixel module drives WS2812/SK6812-style addressable LEDs from one GPIO using the ESP32 RMT peripheral. Use it for status lights, indicators, simple animations, progress bars, alerts, and small decorative LED strips.

Quick example

import neopixel
import system

strip = neopixel.Strip(pin=18, count=8)
strip.set_pixel(0, 255, 0, 0)
strip.show()

def pulse():
    strip.fill(0, 24, 80)
    strip.show()

system.schedule("led_pulse", 1000, 1000, -1, pulse)

rgbw = neopixel.Strip(pin=19, count=16, order="grbw", brightness=0.35)
rgbw.rainbow()

importneopixel

Addressable RGB/RGBW LED strip module.

The neopixel module drives WS2812/SK6812-style addressable LEDs from one GPIO using the ESP32 RMT peripheral. Use it for status lights, indicators, simple animations, progress bars, alerts, and small decorative LED strips.

API 27 available

neopixel.Strip(pin: int, count: int, order: any = None, brightness: int = None, reset_us: int = None) -> str

Create an independent addressable LED strip.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO output pin connected to the strip data input.
count int positional or keyword Yes Number of LEDs in the strip.
order any positional or keyword No Optional color byte order. Defaults to "grb". Use "rgb", "grb", "brg", or a four-channel order such as "grbw" for RGBW.
brightness int positional or keyword No Optional global brightness multiplier from 0.0 through 1.0. Defaults to 1.0.
reset_us int positional or keyword No Optional reset latch time in microseconds. Defaults to 80.
Returns

str neopixel_strip object. Each strip owns its own native RMT resources, so multiple strips can be used at the same time on different pins.

neopixel.Strip().set_pixel(index: int, r: int, g: int, b: int, w: int = 0) -> bool

Set one pixel in the local strip buffer.

Parameters
Name Type Pass as Required Description
index int positional or keyword Yes Required value.
r int positional or keyword Yes Required value.
g int positional or keyword Yes Required value.
b int positional or keyword Yes Required value.
w int positional or keyword No Optional value. Defaults to 0.

neopixel.Strip().get_pixel(index: int) -> dict

Return index, r, g, b, w, and channel for one buffered pixel.

Parameters
Name Type Pass as Required Description
index int positional or keyword Yes Required value.

neopixel.Strip().fill(r: int, g: int, b: int, w: int = 0) -> bool

Set every pixel in the local strip buffer to one color.

Parameters
Name Type Pass as Required Description
r int positional or keyword Yes Required value.
g int positional or keyword Yes Required value.
b int positional or keyword Yes Required value.
w int positional or keyword No Optional value. Defaults to 0.

neopixel.Strip().clear() -> bool

Turn all LEDs off and write the cleared buffer to the strip.

neopixel.Strip().show() -> bool

Write the current pixel buffer to the strip.

neopixel.Strip().set_brightness(value: float) -> bool

Set the global brightness multiplier from 0.0 through 1.0.

Parameters
Name Type Pass as Required Description
value float positional or keyword Yes Required value.

neopixel.Strip().brightness() -> float

Return the current global brightness multiplier.

neopixel.Strip().count() -> int

Return the number of LEDs in the strip.

neopixel.Strip().info() -> dict

Return strip configuration and native channel information.

neopixel.Strip().rainbow(offset: int = 0) -> bool

Fill the strip with a rainbow frame and write it immediately.

Parameters
Name Type Pass as Required Description
offset int positional or keyword No Optional value. Defaults to 0.

neopixel.Strip().deinit() -> bool

Release the strip and its native resources.

neopixel.Strip().close() -> bool

Alias for deinit().

neopixel.Strip().Example

import neopixel strip = neopixel.Strip(pin=18, count=8, brightness=0.4) strip.fill(0, 0, 255) strip.show()

neopixel.begin(pin: int, count: int, channel: int = None, order: any = None, brightness: int = None, reset_us: int = None) -> bool

Initialize the default addressable LED strip.

Parameters
Name Type Pass as Required Description
pin int positional or keyword Yes GPIO output pin connected to the strip data input.
count int positional or keyword Yes Number of LEDs in the strip.
channel int positional or keyword No Optional native strip channel. Defaults to 0. Supported channels are 0 through 3.
order any positional or keyword No Optional color byte order. Defaults to "grb". Use "rgb", "grb", "brg", or a four-channel order such as "grbw" for RGBW.
brightness int positional or keyword No Optional global brightness multiplier from 0.0 through 1.0. Defaults to 1.0.
reset_us int positional or keyword No Optional reset latch time in microseconds. Defaults to 80.
Returns

bool True when the RMT channel and pixel buffers are ready. New code should prefer neopixel.Strip(...) for multiple independent strips.

neopixel.set_pixel(index: any, r: any, g: any, b: any, w: any = None, channel: int = None) -> bool

Set one pixel in the local strip buffer.

Parameters
Name Type Pass as Required Description
index any positional or keyword Yes Zero-based LED index.
r any positional or keyword Yes Red intensity from 0 through 255.
g any positional or keyword Yes Green intensity from 0 through 255.
b any positional or keyword Yes Blue intensity from 0 through 255.
w any positional or keyword No Optional white intensity for RGBW strips. Defaults to 0.
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when the buffer was updated. Call show() to write it to the strip.

neopixel.get_pixel(index: any, channel: int = None) -> dict

Read one pixel from the local strip buffer.

Parameters
Name Type Pass as Required Description
index any positional or keyword Yes Zero-based LED index.
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

dict Dict with index, r, g, b, w, and channel fields.

neopixel.fill(r: any, g: any, b: any, w: any = None, channel: int = None) -> bool

Set every pixel in the local strip buffer to one color.

Parameters
Name Type Pass as Required Description
r any positional or keyword Yes Red intensity from 0 through 255.
g any positional or keyword Yes Green intensity from 0 through 255.
b any positional or keyword Yes Blue intensity from 0 through 255.
w any positional or keyword No Optional white intensity for RGBW strips. Defaults to 0.
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when the buffer was updated. Call show() to write it to the strip.

neopixel.clear(channel: int = None) -> bool

Turn all LEDs off and write the cleared buffer to the strip.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when the off frame was transmitted.

neopixel.show(channel: int = None) -> bool

Write the current pixel buffer to the strip.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when the frame was transmitted.

neopixel.set_brightness(value: any, channel: int = None) -> bool

Set global strip brightness.

Parameters
Name Type Pass as Required Description
value any positional or keyword Yes Brightness multiplier from 0.0 through 1.0.
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when the brightness value was accepted. Call show() to apply it to visible LEDs.

neopixel.brightness(channel: int = None) -> float

Read global strip brightness.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

float Float brightness multiplier.

neopixel.count(channel: int = None) -> int

Read the number of LEDs in a strip.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

int Integer LED count.

neopixel.info(channel: int = None) -> dict

Return strip configuration.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

dict Dict with initialized, channel, pin, count, order, bytes_per_pixel, brightness, and reset_us fields.

neopixel.deinit(channel: int = None) -> bool

Release a strip channel and its RMT resources.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when an initialized strip was released.

neopixel.wheel(pos: any) -> dict

Return a rainbow color for a 0-255 wheel position.

Parameters
Name Type Pass as Required Description
pos any positional or keyword Yes Color wheel position. Values wrap at 255.
Returns

dict Dict with r, g, b, and w fields.

neopixel.rainbow(offset: float = None, channel: int = None) -> bool

Fill the strip with a rainbow frame and write it immediately.

Parameters
Name Type Pass as Required Description
offset float positional or keyword No Optional color wheel offset. Defaults to 0.
channel int positional or keyword No Optional strip channel. Defaults to 0.
Returns

bool True when the rainbow frame was transmitted.