RGBLEDS
Matrix, Text & Sprite libraries for use with FastLED
Install / Use
/learn @AaronLiddiment/RGBLEDSREADME
WILL NO LONGER BE MAINTAINED
SEE SEPARATE CLASSES OFF THE ROOT OF MY GITHUB
cLEDSprites Instructions
Overview
This class allows you to define sprite shapes using 1, 3, 7 or 15 colour palettes. The drawing order can be controlled and each sprite can be given its own automatic motion with options to allow the sprite to be kept in the display area. Collisions between sprites and display edge detection have also been implemented. Also multiple images can be set for each sprite with automatic change controls allowing easy animation.
Initialise
In order to use the class you must have the following header files included in your program:-
#include <FastLED.h>
#include <LEDMatrix.h>
#include <LEDSprites.h>
You must declare an instance of the cLEDMatrix class as this is used to modify the LED data according to the matrix dimensions and layout.
cLEDMatrix<32, 16, HORIZONTAL_ZIGZAG_MATRIX> leds;
The LED array is allocated in the matrix class but the address of the array can be obtained by using '[0]' after the matrix variable name and '.Size()' to obtain the number of LED's:-
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
Then finally you can declare the cLEDSprites class variable:-
cLEDSprites Sprites(&leds);
This class is the control class for the Sprites whereas cSprite is the class for defining individual sprites that can then be registered and used using the cLEDSprites class.
cSprite Shape(SHAPE_WIDTH, SHAPE_HEIGHT, ShapeData, 1, _1BIT, ColTable, ShapeData);
THERE IS FAR MORE TO BE WRITTEN HERE, BUT FOR NOW HAVE A LOOK AT THE EXAMPLES PROVIDED ;-)
cLEDMatrix Instructions
Overview
This class aims to make using a matrix of LED's much simpler by allowing you to use x and y to access it. It also copes with many wiring schemes while still allowing (0,0) to be defined as any of the corners. Plus it adds several mirroring and primitive line and shape drawing functions.
Initialise
In order to use the class you must have the following header files included in your program:-
#include <FastLED.h>
#include <LEDMatrix.h>
You must declare an instance of the cLEDMatrix class as this is used to modify the LED data according to the matrix dimensions and layout. Personally I use defines to make this clearer in the code, such as:-
#define MATRIX_WIDTH 68
#define MATRIX_HEIGHT 7
#define MATRIX_TYPE HORIZONTAL_ZIGZAG_MATRIX
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
There are four matrix types which are delcared at the top of the LEDMatrix header file. HORIZONTAL_MATRIX, VERTICAL_MATRIX, HORIZONTAL_ZIGZAG_MATRIX and VERTICAL_ZIGZAG_MATRIX. If your wired origin is not in the corner that you would like as (0, 0) you can make the appropriate dimension negative to reverse that axis. The LED array is allocated in the matrix class but the address of the array can be obtained by using '[0]' after the matrix variable name and '.Size()' to obtain the number of LED's:-
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
Functions
int Size();
Returns the total number of LEDs.
int Width();
Returns the matrix width.
CRGB *matrix[x]
Returns the memory address of the LED x.
CRGB &matrix(x, y)
Allows you to set an LED with a CRGB colour value.
HorizontalMirror();
Mirrors the matrix horizontally.
VerticalMirror();
Mirrors the matrix vertically.
QuadrantMirror();
Mirrors the matrix bottom left quadrant to the other three.
QuadrantRotateMirror();
Rotates the matrix bottom left quadrant to the other three.
TriangleTopMirror();
Mirrors the matrix upper left corner to the bottom right corner.
TriangleBottomMirror();
Mirrors the matrix bottom left corner to the top right corner.
QuadrantTopTriangleMirror();
Mirrors the matrix bottom left corner quadrants upper left corner to its bottom right corner.
QuadrantBottomTriangleMirror();
Mirrors the matrix bottom left corner quadrants bottom left corner to its upper right corner.
DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col);
Draws a line from (x0, y0) to (x1, y1) with Col.
DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col);
Draws a rectangle (x0, y0) to (x1, y1) with Col.
DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col);
Draws a circle with center (xc, yc) and a radius of r with Col.
DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col);
Draws a filled rectangle (x0, y0) to (x1, y1) with Col.
DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col);
Draws a filled circle with center (xc, yc) and a radius of r with Col.
cLEDText Instructions
Overview
The aim of this class is to provide a flexible way of displaying static or scrolling text on LED displays using the FastLED library. On each update it will fully render the visible window rather than shifting and updating just the new data, this makes it a frame based system allowing text to be overlaid on other patterns/effects. Version 3 now removes the 8 pixel font width limit. Note that the font bits must now be defined from the MSB down so for a 12 pixel font 0xff 0xf0 are the bits used. Also the first four 8 bit values in the font data array specify the width, height, base char and uppper char, which makes font changes easier.
Initialise
In order to use the class you must have the following header files included in your program:-
#include <FastLED.h>
#include <LEDMatrix.h>
#include <LEDText.h>
You will also need some font data, which due to its size, is generally better to be placed in a header file. I have provided 2 font header files as a start. These are FontMatrise.h and FontRobotron.h and will be covered further in the Functions bit.
You must then declare an instance of the cLEDMatrix class as this is used to modify the LED data according to the matrix dimensions and layout.
cLEDMatrix<64, 8, HORIZONTAL_ZIGZAG_MATRIX> leds;
The LED array is allocated in the matrix class but the address of the array can be obtained by using '[0]' after the matrix variable name and '.Size()' to obtain the number of LED's:-
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
Then finally you can declare the cLEDText class variable:-
cLEDText ScrollingMsg;
Functions
SetFont(const uint8_t *FontData);
This function should be called as part of your setup routine and must be called at least once for each instance of cTextScroller, but may be called at any time to change the font. I have provided 3 font header files to get you started as mentioned above. Example:-
#include <FontMatrise.h>
ScrollingMsg.SetFont(MatriseFontData);
FontWidth();
Returns the selected font width as a uint8_t
FontHeight();
Returns the selected font height as a uint8_t
Init(cLEDMatrixBase *Matrix, int16_t Width, int16_t Height, int16_t OriginX = 0, int16_t OriginY = 0);
This function should also be called as part of your setup routine and again must be called at least once for each instance of cLEDText. 'Matrix' parameter should be a pointer to your cLEDMatrix instance. 'Width' and 'Height' are the dimensions of the area in which the text will be displayed. 'OriginX' and 'OriginY' are the matrix coordinates of the bottom left corner of the area. NOTE: The dimensions and origin provided here are independent of the LED Matrix size, they can be smaller to restrict text to a portion of the display or larger to allow control over where the text stops when using Delay control codes. The default colour mode is bright white, RGB. Example:-
ScrollingMsg.Init(&LEDMatrix, MESSAGE_WIDTH, MESSAGE_HEIGHT, MESSAGE_X, MESSAGE_Y);
SetBackgroundMode(uint16_t Options, uint8_t Dimming = 0x00);
This function allows you to set the background mode and optionally if the mode is BACKGND_DIMMING, the dimming amount (BACKGND_ERASE, BACKGND_LEAVE, BACKGND_DIMMING).
SetScrollDirection(uint16_t Options);
This function allows you to set the scrolling direction (SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, SCROLL_DOWN)
SetTextDirection(uint16_t Options);
This function allows you to set the character direction (CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT)
SetTextColrOptions(uint16_t Options, uint8_t ColA1 = 0xff, uint8_t ColA2 = 0xff, uint8_t ColA3 = 0xff, uint8_t ColB1 = 0xff, uint8_t ColB2 = 0xff, uint8_t ColB3 = 0xff);
This function allows you to set the text mode and colour. You can use a combination of the defines for flexible colour control (COLR_RGB, COLR_HSV, COLR_GRAD_CV, COLR_GRAD_AV, COLR_GRAD_CH, COLR_GRAD_AH). If you are just setting single colour mode you only need to provide the first three unit8_t's. There are two other colours modes (COLR_EMPTY, COLR_DIMMING). The EMPTY one will leave any '1' bits
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
