LED API
Overview
The LED system in MatrixOS provides control over the 8x8 LED matrix with layer support, real-time updates, and cross-fade animations. The LED API is available as MatrixOS.LED
and is imported by default.
For some LED functions, you can specify a layer ID. If you don't specify a layer ID, the API will use layer 255 (the topmost layer). Changes only take effect when you call Update()
.
For immediate updates, write to layer 0 (the active buffer). Changes render immediately unless paused with PauseUpdate(True)
. This is ideal for real-time effects but may cause flickering.
The Python LED API is implemented in Applications/Python/PikaPython/MatrixOS_LED.py with type hints in Applications/Python/PikaPython/_MatrixOS_LED.pyi.
Constants
The LED API uses the following predefined constants:
CURRENT_LAYER = 255
- Refers to the current active layer when no layer is specifiedCROSSFADE_DURATION = 200
- Default crossfade duration in milliseconds
MatrixOS.LED.NextBrightness
def NextBrightness() -> None
Cycles to the next predefined brightness level for the LEDs.
Example:
MatrixOS.LED.NextBrightness()
MatrixOS.LED.SetBrightness
def SetBrightness(brightness: int) -> None
Sets the brightness level of the LEDs.
Parameters:
brightness
(int
): Brightness level (0-255)
Example:
MatrixOS.LED.SetBrightness(128) # Set to 50% brightness
MatrixOS.LED.SetBrightnessMultiplier
def SetBrightnessMultiplier(partition_name: str, multiplier: float) -> bool
Applies a brightness multiplier to a specific LED partition.
Parameters:
partition_name
(str
): Name of the partition to modifymultiplier
(float
): Brightness multiplier
Returns:
bool
: True if successful
Example:
MatrixOS.LED.SetBrightnessMultiplier("keypad", 0.8) # Set keypad brightness to 0.8x
MatrixOS.LED.SetColor
def SetColor(xy: Point, color: Color, layer: int = CURRENT_LAYER) -> None
Sets the color of a specific LED at coordinates (x, y).
Parameters:
xy
(Point
): LED coordinates (0-7 for both x and y)color
(Color
): Color to setlayer
(int
, optional): Layer ID to write to (defaults to CURRENT_LAYER)
Example:
point = Point(2, 3)
red = Color(255, 0, 0)
MatrixOS.LED.SetColor(point, red) # Set LED at (2,3) to red
MatrixOS.LED.SetColorByID
def SetColorByID(id: int, color: Color, layer: int = CURRENT_LAYER) -> None
Sets the color of an LED by its ID (0-63 for 8x8 matrix).
Parameters:
id
(int
): LED ID (0-63)color
(Color
): Color to setlayer
(int
, optional): Layer ID to write to (defaults to CURRENT_LAYER)
Example:
MatrixOS.LED.SetColorByID(0, Color(0, 255, 0)) # Set first LED to green
MatrixOS.LED.Fill
def Fill(color: Color, layer: int = CURRENT_LAYER) -> None
Fills all LEDs with the specified color.
Parameters:
color
(Color
): Color to fill withlayer
(int
, optional): Layer ID to write to (defaults to CURRENT_LAYER)
Example:
MatrixOS.LED.Fill(Color(0, 0, 255)) # Fill all LEDs with blue
MatrixOS.LED.FillPartition
def FillPartition(partition: str, color: Color, layer: int = CURRENT_LAYER) -> bool
Fills a specific LED partition with the specified color.
Parameters:
partition
(str
): Partition name (e.g., "keypad", "function")color
(Color
): Color to fill withlayer
(int
, optional): Layer ID to write to (defaults to CURRENT_LAYER)
Returns:
bool
: True if successful
Example:
MatrixOS.LED.FillPartition("keypad", Color(255, 255, 0)) # Fill keypad with yellow
MatrixOS.LED.Update
def Update(layer: int = CURRENT_LAYER) -> None