Draw on an LED matrix using a Raspberry Pi and Typescript and Node.js. Takes a declarative approach to the excellent alexeden/rpi-led-matrix and extends some of its features. Manage sections of the board independently, draw shapes, text, images, and some simple effects. Watch this space. Check implementation branch for latest updates.
MIT License
Add drawing facilities to the excellent alexeden/rpi-led-matrix. Takes a declarative approach to drawing on the matrix. Manage sections of the board independently, draw shapes, text, images, and some simple effects.
Check out wesleytabaka/rpi-led-matrix-painter-example for a working example of the library. View on YouTube
Install with npm using:
npm i rpi-led-matrix-painter --save
Import into your app using:
import * as Board from "rpi-led-matrix-painter";
"Board" will contain the following TS modules:
Here is the public API. To get started, create a new Painter instance:
import * as Board from "rpi-led-matrix-painter";
export class MyClass {
private mypainter = new Board.Painter(
{
...Board.RpiLedMatrix.LedMatrix.defaultMatrixOptions(),
rows: 32, // LED rows per panel
cols: 64, // LED columns per panel
chainLength: 2 // Number of panels chained together
},
{
...Board.RpiLedMatrix.LedMatrix.defaultRuntimeOptions()
}
);
}
To create a CanvasSection the full size of both panels, assuming they're laid out next to each other horizontally...
this.mypainter.getCanvas().addCanvasSection(new Board.CanvasSection("mycanvassection", 0, 0, 1, 128, 32, [], true));
To set the new CanvasSection, mycanvassection to read something like "Hello, world!"...
this.mypainter.getCanvas().getCanvasSection("mycanvassection")?.setRepresentation([
{
id: "helloworld",
drawMode: Board.DrawMode.TEXT,
color: 0x800000,
drawModeOptions: {font: "5x7", fontPath: "/home/pi/code/rpi-led-matrix-painter-test/fonts/5x7.bdf"},
points: {x: 0, y:0, z: 1},
text: "Hello, world!",
layer: 1
}
]);
The CanvasSection.setRepresentation() method takes an array of PaintingInstruction. The format of this can vary depending on the drawMode. For example, when using a DrawMode of LINE, the "points" property should be an array of Point. When using a DrawMode of TEXT, the "points" property should be one Point. The properties "id", "drawMode", and "color" are all required all of the time. When you're ready to draw to the Canvas, call paint() on the Painter object...
this.mypainter.paint();
That's it! Below is the public API spec.
interface DrawModeOption {
fill?: boolean,
font?: string,
fontPath?: string,
effects?: Effect[]
}
interface Effect {
effectType: EffectType
effectOptions: EffectOptions;
}
interface EffectOptions {
rate: number // Expresses pixels per repaint.
}
interface PaintingInstruction {
id: string,
drawMode: DrawMode,
points: Point | Point[],
color: number,
layer: number,
drawModeOptions?: DrawModeOption,
width?: number,
height?: number,
text?: string,
imagePath?: string,
buffer?: Buffer
}
interface Point {
x: number,
y: number,
z: number
}
This is a re-export of wesleytabaka/rpi-led-matrix which is forked off of alexeden/rpi-led-matrix. My fork just adds the filled shapes functionality.
For bugs or feature requests create an issue and tag it accordingly.
To contribute, fork and create a Pull Request.