Skip to content

led

Module: led
Source: modules/led.py

The led module provides the Led class, a high-level wrapper around MicroPython’s neopixel library for the single WS2812 RGB LED on the nXPico M (GPIO23).

The following module-level constants are defined as (r, g, b) tuples and used internally by the shortcut methods:

ConstantValue
RED(255, 0, 0)
GREEN(0, 255, 0)
BLUE(0, 0, 255)
WHITE(255, 255, 255)
YELLOW(255, 255, 0)
CYAN(0, 255, 255)
MAGENTA(255, 0, 255)
ORANGE(255, 128, 0)
OFF(0, 0, 0)
from led import Led

Initialises the LED on GPIO23 and sets it to off [0, 0, 0].


Set the LED to an arbitrary RGB color.

ParameterTypeDescription
valuelistA 3-element list [r, g, b] with values in the range 0–255.

Raises ValueError if:

  • value is not a list of exactly 3 elements.
  • Any element is not an int.
  • Any element is outside the range 0–255.
led.set_color([255, 128, 0]) # warm orange

Returns a copy of the current color as [r, g, b].

color = led.get_value() # e.g. [255, 128, 0]

Each method calls set_color() with the corresponding constant.

MethodColor
red()[255, 0, 0]
green()[0, 255, 0]
blue()[0, 0, 255]
white()[255, 255, 255]
yellow()[255, 255, 0]
cyan()[0, 255, 255]
magenta()[255, 0, 255]
orange()[255, 128, 0]
off()[0, 0, 0]

All return None.

from led import Led
rgb = Led()
rgb.red()
rgb.set_color([0, 100, 200])
print(rgb.get_value()) # [0, 100, 200]
rgb.off()