LEDMatrix


GitHub version GitHub version GitHub version

A fork of (cLEDMatrix by Aaron Liddiment) and FastLED port of (Adafruit-NeoMatrix) by using the graphics library FastLED-GFX (based on Adafruit-GFX-Library)

Once you have downloaded the Zip file, it should be extracted into your Arduino Libraries folder and the folder renamed to "LEDMatrix".

The LEDMatrix library based on cLEDMatrix and Adafruit-NeoMatrix to create two-dimensional graphic displays using FastLED. You can then easily draw shapes, text and animation without having to calculate every X/Y pixel position. Larger displays can be formed using sections of LED strip / matrices, as shown in the photo below.
Table of Contents Espruino Pico OLED NFC

Single Matrix (Example)


Parameters

Parameter Description
Parameter 1 width of matrix
Parameter 2 height of matrix
Parameter 3 matrix layout flags, add together as needed

Includes

#include <FastLED.h>
#include <FastLED_GFX.h>
#include <LEDMatrix.h>

Decleration

// declare FastLED (matrix / LED strip)
#define LED_PIN        2
#define COLOR_ORDER    GRB
#define CHIPSET        WS2812B

// declare matrix
#define MATRIX_WIDTH   5 // width of matrix
#define MATRIX_HEIGHT  8 // height of matrix
#define MATRIX_TYPE    (MTX_MATRIX_TOP + MTX_MATRIX_RIGHT + MTX_MATRIX_COLUMNS + MTX_MATRIX_PROGRESSIVE) // matrix layout flags, add together as needed

// create our matrix based on matrix definition
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> matrix;

Initialize FastLED

void setup() {
  // initial FastLED by using CRGB led source from our matrix class
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(matrix[0], matrix.Size());
  FastLED.setBrightness(127);
  FastLED.clear(true);
}

Tile Matrix (Example)


Parameters

Parameter Description
Parameter 1 width of EACH NEOPIXEL MATRIX (not total display)
Parameter 2 height of each matrix
Parameter 3 matrix layout flags, add together as needed
Parameter 4 number of matrices arranged horizontally
Parameter 5 number of matrices arranged vertically

Includes

#include <FastLED.h>
#include <FastLED_GFX.h>
#include <LEDMatrix.h>

Decleration

// declare FastLED (matrix / LED strip)
#define LED_PIN        2
#define COLOR_ORDER    GRB
#define CHIPSET        WS2812B

// declare matrix
#define MATRIX_WIDTH        16 // width of EACH NEOPIXEL MATRIX (not total display)
#define MATRIX_HEIGHT       16 // height of each matrix
#define MATRIX_TILE_H       4  // number of matrices arranged horizontally
#define MATRIX_TILE_V       1  // number of matrices arranged vertically
#define MATRIX_TYPE        (MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG + MTX_TILE_TOP + MTX_TILE_LEFT + MTX_TILE_ROWS) // matrix layout flags, add together as needed
#define MATRIX_SIZE        (MATRIX_WIDTH*MATRIX_HEIGHT)

// create our matrix based on matrix definition
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE, MATRIX_TILE_H, MATRIX_TILE_V> matrix;

Initialize FastLED

void setup() {
  // initial FastLED by using CRGB led source from our matrix class
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(matrix[0], matrix.Size());
  FastLED.setBrightness(127);
  FastLED.clear(true);
}

Initialize FastLED (multiple controller)

void setup() {
  // initial FastLED with multiple controller, by using CRGB led source from each matrix panal
  // panel 1 (from   0 to  255)
  FastLED.addLeds<WS2812B, PANEL_1_DATA_PIN, GRB>(matrix[0], 0, MATRIX_SIZE);
  // panel 2 (from 255 to  511)
  FastLED.addLeds<APA102, PANEL_2_DATA_PIN, PANEL_2_CLOCK_PIN, RGB>(matrix[0], 1*MATRIX_SIZE, MATRIX_SIZE);
  // panel 3 (from 512 to  767)
  FastLED.addLeds<SK9822, PANEL_3_DATA_PIN, PANEL_3_CLOCK_PIN, BGR>(matrix[0], 2*MATRIX_SIZE, MATRIX_SIZE);
  // panel 4 (from 768 to 1023)
  FastLED.addLeds<WS2812B, PANEL_4_DATA_PIN, GRB>(matrix[0], 3*MATRIX_SIZE, MATRIX_SIZE);
  FastLED.setBrightness(127);
  FastLED.clear(true);
}

Available Methods

uint16_t mXY(uint16_t x, uint16_t y)
void SetLEDArray(struct CRGB *pLED)

struct CRGB *operator[](int n)
struct CRGB &operator()(int16_t x, int16_t y)
struct CRGB &operator()(int16_t i)

int Size()
int Width()
int Height()

void HorizontalMirror(bool FullHeight = true)
void VerticalMirror()
void QuadrantMirror()
void QuadrantRotateMirror()
void TriangleTopMirror(bool FullHeight = true)
void TriangleBottomMirror(bool FullHeight = true)
void QuadrantTopTriangleMirror()
void QuadrantBottomTriangleMirror()

void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color)
void DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color)
void DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color)
void DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color)
void DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color)

void drawPixel(int n, CRGB color)
void drawPixel(int16_t x, int16_t y, CRGB color)
struct CRGB & pixel(int n)
struct CRGB & pixel(int16_t x, int16_t y)
void fillScreen(CRGB color)
void setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t))

Graphic Library (FastLED-GFX)


Simple FastLED port of (Adafruit-GFX-Library)

Available Methods

void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color)
void drawFastVLine(int16_t x, int16_t y, int16_t h, CRGB color)
void drawFastHLine(int16_t x, int16_t y, int16_t w, CRGB color)
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, CRGB color)
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, CRGB color)
void fillScreen(CRGB color)
void invertDisplay(boolean i)

void drawCircle(int16_t x0, int16_t y0, int16_t r, CRGB color)
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, CRGB color)
void fillCircle(int16_t x0, int16_t y0, int16_t r, CRGB color)
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, CRGB color)
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color)
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color)
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, CRGB color)
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, CRGB color)
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, CRGB color)
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, CRGB color, CRGB bg)
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, CRGB color)
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, CRGB color, CRGB bg)
void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, CRGB color)
void drawChar(int16_t x, int16_t y, unsigned char c, CRGB color, CRGB bg, uint8_t size)
void setCursor(int16_t x, int16_t y)
void setTextColor(CRGB c)
void setTextColor(CRGB c, CRGB bg)
void setTextSize(uint8_t s)
void setTextWrap(boolean w)
void setRotation(uint8_t r)
void cp437(boolean x=true)
void setFont(const GFXfont *f = NULL)
void getTextBounds(char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
void getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)

size_t write(uint8_t)

int16_t height(void) const
int16_t width(void) const

uint8_t getRotation(void) const

int16_t getCursorX(void) const
int16_t getCursorY(void) const