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).
Color constants
Section titled “Color constants”The following module-level constants are defined as (r, g, b) tuples and used internally by the shortcut methods:
| Constant | Value |
|---|---|
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) |
Class Led
Section titled “Class Led”from led import LedInitialises the LED on GPIO23 and sets it to off [0, 0, 0].
set_color(value: list) -> None
Section titled “set_color(value: list) -> None”Set the LED to an arbitrary RGB color.
| Parameter | Type | Description |
|---|---|---|
value | list | A 3-element list [r, g, b] with values in the range 0–255. |
Raises ValueError if:
valueis 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 orangeget_value() -> list
Section titled “get_value() -> list”Returns a copy of the current color as [r, g, b].
color = led.get_value() # e.g. [255, 128, 0]Color shortcut methods
Section titled “Color shortcut methods”Each method calls set_color() with the corresponding constant.
| Method | Color |
|---|---|
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.
Example
Section titled “Example”from led import Led
rgb = Led()
rgb.red()rgb.set_color([0, 100, 200])print(rgb.get_value()) # [0, 100, 200]rgb.off()