Skip to content

Jorgen-VikingGod/LEDMatrix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LEDMatrix


Travis build GitHub version FastLED dependencies

A fork of (cLEDMatrix by Aaron Liddiment) and build in some features from (Adafruit-NeoMatrix)

As another option, if you would like full Adafruit::Neomatrix support, you can check this library: https://github.com/marcmerlin/FastLED_NeoMatrix A big plus of access to the full Adafruit GFX compatibility is font support

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 builds a giant two-dimensional graphics array which can be used by 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 tiles of LED strip / matrices - to build one big matrix. Similar to Adafruit-NeoMatrix (see picture below as example).
Table of Contents Espruino Pico OLED NFC

Single Matrix (Example)


Parameters

Parameter Description
Parameter 1 width of matrix (negative for reverse order)
Parameter 2 height of matrix (negative for reverse order)
Parameter 3 MatrixType_t = matrix layout type
enum MatrixType_t { HORIZONTAL_MATRIX,
                    VERTICAL_MATRIX,
                    HORIZONTAL_ZIGZAG_MATRIX,
                    VERTICAL_ZIGZAG_MATRIX };

enum BlockType_t  { HORIZONTAL_BLOCKS,
                    VERTICAL_BLOCKS,
                    HORIZONTAL_ZIGZAG_BLOCKS,
                    VERTICAL_ZIGZAG_BLOCKS };

Includes

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

Declaration

// Change the next defines to match your matrix type and size
#define DATA_PIN            D5

#define COLOR_ORDER         GRB
#define CHIPSET             WS2812B

// initial matrix layout (to get led strip index by x/y)
#define MATRIX_WIDTH   11
#define MATRIX_HEIGHT  11
#define MATRIX_TYPE    HORIZONTAL_ZIGZAG_MATRIX
#define MATRIX_SIZE    (MATRIX_WIDTH*MATRIX_HEIGHT)
#define NUMPIXELS      MATRIX_SIZE

// create our matrix based on matrix definition
cLEDMatrix<[-]MATRIX_WIDTH, [-]MATRIX_HEIGHT, MATRIX_TYPE> leds;
To cope with a matrix wired right to left, add - in front of your width. Similarly if the matrix is wired down to up, add - in front of height.

Initialize FastLED

void setup() {
  // initial FastLED by using CRGB led source from our matrix class
  FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds[0], leds.Size()).setCorrection(TypicalSMD5050);
  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 MatrixType_t = matrix layout type
Parameter 4 number of matrices arranged horizontally
Parameter 5 number of matrices arranged vertically
Parameter 6 BlockType_t = layout of each matrix tile
enum MatrixType_t { HORIZONTAL_MATRIX,
                    VERTICAL_MATRIX,
                    HORIZONTAL_ZIGZAG_MATRIX,
                    VERTICAL_ZIGZAG_MATRIX };

enum BlockType_t  { HORIZONTAL_BLOCKS,
                    VERTICAL_BLOCKS,
                    HORIZONTAL_ZIGZAG_BLOCKS,
                    VERTICAL_ZIGZAG_BLOCKS };

Includes

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

Declaration

// Change the next defines to match your matrix type and size
#define DATA_PIN            D2
#define CLOCK_PIN           D1
#define DATA2_PIN           D4
#define CLOCK2_PIN          D3

#define COLOR_ORDER         BGR
#define CHIPSET             APA102

#define MATRIX_TILE_WIDTH   16 // width of EACH NEOPIXEL MATRIX (not total display)
#define MATRIX_TILE_HEIGHT  8 // height of each matrix
#define MATRIX_TILE_H       1  // number of matrices arranged horizontally (negative for reverse order)
#define MATRIX_TILE_V       8  // number of matrices arranged vertically (negative for reverse order)
#define MATRIX_SIZE         (MATRIX_WIDTH*MATRIX_HEIGHT)
#define MATRIX_PANEL        (MATRIX_WIDTH*MATRIX_HEIGHT)

#define MATRIX_WIDTH        (MATRIX_TILE_WIDTH*MATRIX_TILE_H)
#define MATRIX_HEIGHT       (MATRIX_TILE_HEIGHT*MATRIX_TILE_V)

#define NUM_LEDS            (MATRIX_WIDTH*MATRIX_HEIGHT)

// create our matrix based on matrix definition
cLEDMatrix<[-]MATRIX_TILE_WIDTH, [-]MATRIX_TILE_HEIGHT, HORIZONTAL_ZIGZAG_MATRIX, [-]MATRIX_TILE_H, [-]MATRIX_TILE_V, VERTICAL_BLOCKS> leds;

Initialize FastLED

void setup() {
  // initial FastLED by using CRGB led source from our matrix class
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.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  
  FastLED.addLeds<CHIPSET, DATA_PIN,  CLOCK_PIN,  COLOR_ORDER>(leds[0], 0,             leds.Size()/2).setCorrection(TypicalSMD5050);
  FastLED.addLeds<CHIPSET, DATA2_PIN, CLOCK2_PIN, COLOR_ORDER>(leds[0], leds.Size()/2, leds.Size()/2).setCorrection(TypicalSMD5050);
  FastLED.setBrightness(127);
  FastLED.clear(true);
}

Available Methods

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

void ShiftLeft(void)
void ShiftRight(void)
void ShiftDown(void)
void ShiftUp(void)

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 DrawPixel(int16_t x, int16_t y, CRGB color)
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)

Compatibility with SmartMatrix supported RGBPanels

NeoMatrix displays can be big, typically 1cm^2 per pixel, sometimes more. If you need Matrices that are both smaller and cheaper, you can use RGBPanels which are supported by SmartMatrix: https://github.com/pixelmatix/SmartMatrix
If you also install https://github.com/marcmerlin/SmartMatrix_GFX you get a compat layer that lets you run FastLED and LEDMatrix code. See https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/tree/master/LEDMatrix for examples.

Running/Debugging your LEDMatrix code on a Linux Computer

For ease of development, you can develop and debug your code on linux using ArduinoOnPc-FastLED-GFX-LEDMatrix.

http://marc.merlins.org/perso/arduino/post_2020-01-24_Running-Arduino-code-with-2D-FastLED_-Adafruit_GFX_-and-LEDMatrix-displays-on-Linux.html introduces https://github.com/marcmerlin/ArduinoOnPc-FastLED-GFX-LEDMatrix

This solution allows you to build arduino code so that it works on linux (you can run it in a VM if you aren't running linux natively) and uses these layers:

Packages

No packages published

Languages

  • C++ 94.0%
  • Shell 6.0%