LED Matrix
#Description
A small display consisting of LEDs. It is great for pixelated images and data.
#Links
#Aliases
- MY9221
#Functions
#JavaScript / Node.js
LEDMatrixextends I2cComponentBaseLEDMatrix component for controlling Grove RGB LED Matrix w/Driver (8x8 RGB matrix). Uses I2C communication (address 0x65) with built-in STM32F031 controller.
#Value type
interface LEDMatrixValue {
power: boolean;
type: "bitmap" | "full-color" | "text" | "animation";
color: string;
text: string;
bitmap: number[];
displayDuration: number;
animation: number;
}#Constructor options
| Option | Type | Required | Description | Inherited from |
|---|---|---|---|---|
orientation | number | optional | — | |
pin | I2CPinID | required | — | I2cComponentBase |
#Events
| Event | Parameters | Description |
|---|---|---|
change | value: LEDMatrixValue | — |
#Methods
setColor(color: string)Set entire matrix to a single RGB color.
displayText(text: string, durationMs: number, colorName: string)Display scrolling text with specified color name and duration.
displayNumber(num: number, durationMs: number, colorName: string)Display a number with specified color name and duration.
displayAnimation(animationId: number, durationMs: number)Play a built-in color animation.
displayColorWave(colorName: string, durationMs: number)Display color wave animation.
displayColorBar(percent: number)Display color bar at specified percentage.
displayEmoji(emojiIndex: number)Display built-in emoji by index.
drawBitmap(bitmap: number[])Draw a custom 8x8 bitmap.
clear()Turn off all LEDs (clear display).
powerOff()Power off the matrix (alias for clear).
get i2cId→ I2CPinIDfrom I2cComponentBaseThe resolved I2C pin ID (e.g. "i2c-0"). Useful for logging or passing back to the Arduino sketch.
#Example
import { Board, LEDMatrix } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const lEDMatrix = new LEDMatrix({ board, pin: "example" });#C++ (Arduino)
Direct I2C implementation for the Grove RGB LED Matrix (STM32F031 + MY9221). 8x8 RGB LED Matrix with built-in MCU controller. This class communicates directly via I2C without requiring external libraries. Based on the Seeed Studio protocol: https://github.com/Seeed-Studio/Seeed_RGB_LED_Matrix Supported operations: - setFullColor(r, g, b) - Set entire matrix to single RGB color - setFullColor(Color) - Set entire matrix using blokdots::Color - displayText(text, duration, color) - Display scrolling text with color name - displayNumber(num, duration, color)- Display a number with color name - displayAnimation(id, duration) - Play built-in color animation by ID - clear() - Turn off all LEDs - powerOff() - Alias for clear() Animation IDs: - 0: big square - 1: small square - 2: rainbow cycle - 3: fire - 4: walking child - 5: broken heart Text colors: - "red", "orange", "yellow", "green", "cyan", "blue", "purple", "pink", "white", "black" Note: This component uses I2C communication (default address 0x65).
#Required libraries
#include <Wire.h>— Wire
#Setup
#include "blokdots.h"
LEDMatrix myComponent();#Constructor
LEDMatrix(orientation, wire)Basic constructor (no EventBus)
| Parameter | Type | Default |
|---|---|---|
orientation | uint8_t | 3 |
wire | TwoWire | Wire |
LEDMatrix(bus, orientation, evtChange, wire)Constructor with EventBus for trigger support
| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
orientation | uint8_t | required |
evtChange | uint8_t | required |
wire | TwoWire | Wire |
#Methods
setFullColor(r, g, b)Set entire matrix to a single RGB color
| Parameter | Type | Default |
|---|---|---|
r | uint8_t | required |
g | uint8_t | required |
b | uint8_t | required |
setFullColor(hex)Hex color support
| Parameter | Type | Default |
|---|---|---|
hex | const char | required |
displayText(text, durationMs, colorName)Display scrolling text with specified color name and duration (in milliseconds)
| Parameter | Type | Default |
|---|---|---|
text | const char | required |
durationMs | uint32_t | required |
colorName | const char | required |
displayNumber(num, durationMs, colorName)Display a number with specified color name and duration (in milliseconds)
| Parameter | Type | Default |
|---|---|---|
num | int16_t | required |
durationMs | uint32_t | required |
colorName | const char | required |
displayEmoji(emojiIndex)Display built-in emoji by index
| Parameter | Type | Default |
|---|---|---|
emojiIndex | uint8_t | required |
displayAnimation(animationId, durationMs)3 = fire, 4 = walking child, 5 = broken heart
| Parameter | Type | Default |
|---|---|---|
animationId | uint8_t | required |
durationMs | uint32_t | required |
displayColorWave(colorName, durationMs)Display color wave animation with specified color name and duration
| Parameter | Type | Default |
|---|---|---|
colorName | const char | required |
durationMs | uint32_t | required |
displayColorBar(percent)Display color bar at specified percentage (0-100)
| Parameter | Type | Default |
|---|---|---|
percent | uint8_t | required |
writePixel(index, value)Stage a single pixel value into the bitmap buffer (index 0-63, row by row)
| Parameter | Type | Default |
|---|---|---|
index | uint8_t | required |
value | uint8_t | required |
commitBitmap()1ms delay between each write (required by the controller).
clear()powerOff()isOn()→ boolemittedValue()→ intFor triggers: returns 1 when powered on, 0 when off