From 44f936af0d1c8d5ed0569e922205c73cef6a4ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 29 Apr 2016 17:08:36 +0200 Subject: [PATCH 01/35] merge functionality of Adafruit_NeoMatrix --- LEDMatrix.cpp | 382 ++++---- LEDMatrix.h | 849 +++++++++--------- README.md | 241 +++++ examples/MatrixExample1/MatrixExample1.ino | 7 +- examples/MatrixExample2/MatrixExample2.ino | 5 +- .../MatrixTilesExample/MatrixTilesExample.ino | 122 +++ 6 files changed, 993 insertions(+), 613 deletions(-) create mode 100644 examples/MatrixTilesExample/MatrixTilesExample.ino diff --git a/LEDMatrix.cpp b/LEDMatrix.cpp index 416cc5a..1a8eb93 100644 --- a/LEDMatrix.cpp +++ b/LEDMatrix.cpp @@ -1,90 +1,204 @@ -/* -LEDMatrix V4 class by Aaron Liddiment (c) 2015 - -Inspiration for some of the Matrix functions from Stefan Petrick - -FastLED v3.1 library by Daniel Garcia and Mark Kriegsmann. -Written & tested on a Teensy 3.1 using Arduino V1.6.3 & teensyduino V1.22 -*/ - +/*-------------------------------------------------------------------- + Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix + and on https://github.com/AaronLiddiment/LEDMatrix + replace internal use of NeoPixel library with CRGB array to use with FastLED + + modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) + date: 2016/04/27 + -------------------------------------------------------------------- + Original copyright & description below + -------------------------------------------------------------------- + This file is part of the Adafruit NeoMatrix library. + + NeoMatrix is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + NeoMatrix is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with NeoMatrix. If not, see + . + -------------------------------------------------------------------- + LEDMatrix V4 class by Aaron Liddiment (c) 2015 + Inspiration for some of the Matrix functions from Stefan Petrick + FastLED v3.1 library by Daniel Garcia and Mark Kriegsmann. + Written & tested on a Teensy 3.1 using Arduino V1.6.3 & teensyduino V1.22 + --------------------------------------------------------------------*/ #include #include +#ifdef __AVR__ + #include +#elif defined(ESP8266) + #include +#else + #ifndef pgm_read_byte + #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) + #endif +#endif -cLEDMatrixBase::cLEDMatrixBase() -{ -} +#ifndef _swap_uint16_t +#define _swap_uint16_t(a, b) { uint16_t t = a; a = b; b = t; } +#endif -struct CRGB* cLEDMatrixBase::operator[](int n) -{ +cLEDMatrixBase::cLEDMatrixBase(int w, int h) + : FastLED_GFX(w, h) { } + +struct CRGB* cLEDMatrixBase::operator[](int n) { return(&m_LED[n]); } -struct CRGB& cLEDMatrixBase::operator()(int16_t x, int16_t y) -{ - if ( (x >= 0) && (x < m_Width) && (y >= 0) && (y < m_Height)) +struct CRGB& cLEDMatrixBase::operator()(int16_t x, int16_t y) { + if ( (x >= 0) && (x < _width) && (y >= 0) && (y < _height)) return(m_LED[mXY(x, y)]); else return(m_OutOfBounds); } -struct CRGB& cLEDMatrixBase::operator()(int16_t i) -{ - if ((i >=0) && (i < (m_Width * m_Height))) +struct CRGB& cLEDMatrixBase::operator()(int16_t i) { + if ((i >=0) && (i < (_width * _height))) return(m_LED[i]); else return(m_OutOfBounds); } -void cLEDMatrixBase::HorizontalMirror(bool FullHeight) -{ - int ty, y, x, xx; +uint16_t cLEDMatrixBase::mXY(uint16_t x, uint16_t y) { + if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0; + + int16_t t; + switch(rotation) { + case 1: + t = x; + x = WIDTH - 1 - y; + y = t; + break; + case 2: + x = WIDTH - 1 - x; + y = HEIGHT - 1 - y; + break; + case 3: + t = x; + x = y; + y = HEIGHT - 1 - t; + break; + } + + int tileOffset = 0, pixelOffset; + + if(remapFn) { // Custom X/Y remapping function + pixelOffset = (*remapFn)(x, y); + } else { // Standard single matrix or tiled matrices + uint8_t corner = type & MTX_MATRIX_CORNER; + uint16_t minor, major, majorScale; + + if(tilesX) { // Tiled display, multiple matrices + uint16_t tile; + + minor = x / matrixWidth; // Tile # X/Y; presume row major to + major = y / matrixHeight, // start (will swap later if needed) + x = x - (minor * matrixWidth); // Pixel X/Y within tile + y = y - (major * matrixHeight); // (-* is less math than modulo) + + // Determine corner of entry, flip axes if needed + if(type & MTX_TILE_RIGHT) minor = tilesX - 1 - minor; + if(type & MTX_TILE_BOTTOM) major = tilesY - 1 - major; + + // Determine actual major axis of tiling + if((type & MTX_TILE_AXIS) == MTX_TILE_ROWS) { + majorScale = tilesX; + } else { + _swap_uint16_t(major, minor); + majorScale = tilesY; + } + + // Determine tile number + if((type & MTX_TILE_SEQUENCE) == MTX_TILE_PROGRESSIVE) { + // All tiles in same order + tile = major * majorScale + minor; + } else { + // Zigzag; alternate rows change direction. On these rows, + // this also flips the starting corner of the matrix for the + // pixel math later. + if(major & 1) { + corner ^= MTX_MATRIX_CORNER; + tile = (major + 1) * majorScale - 1 - minor; + } else { + tile = major * majorScale + minor; + } + } + // Index of first pixel in tile + tileOffset = tile * matrixWidth * matrixHeight; + } // else no tiling (handle as single tile) + + // Find pixel number within tile + minor = x; // Presume row major to start (will swap later if needed) + major = y; + + // Determine corner of entry, flip axes if needed + if(corner & MTX_MATRIX_RIGHT) minor = matrixWidth - 1 - minor; + if(corner & MTX_MATRIX_BOTTOM) major = matrixHeight - 1 - major; + + // Determine actual major axis of matrix + if((type & MTX_MATRIX_AXIS) == MTX_MATRIX_ROWS) { + majorScale = matrixWidth; + } else { + _swap_uint16_t(major, minor); + majorScale = matrixHeight; + } + + // Determine pixel number within tile/matrix + if((type & MTX_MATRIX_SEQUENCE) == MTX_MATRIX_PROGRESSIVE) { + // All lines in same order + pixelOffset = major * majorScale + minor; + } else { + // Zigzag; alternate rows change direction. + if(major & 1) pixelOffset = (major + 1) * majorScale - 1 - minor; + else pixelOffset = major * majorScale + minor; + } + } + return (tileOffset + pixelOffset); +} +void cLEDMatrixBase::HorizontalMirror(bool FullHeight) { + int ty, y, x, xx; if (FullHeight) - ty = m_Height - 1; + ty = _height - 1; else - ty = (m_Height / 2); - for (y=ty; y>=0; --y) - { - for (x=(m_Width/2)-1,xx=((m_Width+1)/2); x>=0; --x,++xx) + ty = (_height / 2); + for (y=ty; y>=0; --y) { + for (x=(_width/2)-1,xx=((_width+1)/2); x>=0; --x,++xx) m_LED[mXY(xx, y)] = m_LED[mXY(x, y)]; } } - -void cLEDMatrixBase::VerticalMirror() -{ +void cLEDMatrixBase::VerticalMirror() { int y, yy, x; - - for (y=(m_Height/2)-1,yy=((m_Height+1)/2); y>=0; --y,++yy) - { - for (x=m_Width-1; x>=0; --x) + for (y=(_height/2)-1,yy=((_height+1)/2); y>=0; --y,++yy) { + for (x=_width-1; x>=0; --x) m_LED[mXY(x, yy)] = m_LED[mXY(x, y)]; } } - -void cLEDMatrixBase::QuadrantMirror() -{ +void cLEDMatrixBase::QuadrantMirror() { HorizontalMirror(false); VerticalMirror(); } - -void cLEDMatrixBase::QuadrantRotateMirror() -{ +void cLEDMatrixBase::QuadrantRotateMirror() { int MaxXY, MidXY, x, y, src; - - if (m_Width > m_Height) - MaxXY = m_Height; + if (_width > _height) + MaxXY = _height; else - MaxXY = m_Width; + MaxXY = _width; MidXY = (MaxXY / 2); MaxXY--; - for (x=MidXY-(MaxXY%2); x>=0; --x) - { - for (y=MidXY-(MaxXY%2); y>=0; --y) - { + for (x=MidXY-(MaxXY%2); x>=0; --x) { + for (y=MidXY-(MaxXY%2); y>=0; --y) { src = mXY(x, y); m_LED[mXY(MidXY + y, MidXY - (MaxXY % 2) - x)] = m_LED[src]; m_LED[mXY(MaxXY - x, MaxXY - y)] = m_LED[src]; @@ -93,150 +207,88 @@ void cLEDMatrixBase::QuadrantRotateMirror() } } - -void cLEDMatrixBase::TriangleTopMirror(bool FullHeight) -{ +void cLEDMatrixBase::TriangleTopMirror(bool FullHeight) { int MaxXY, x, y; - - if (m_Width > m_Height) - MaxXY = m_Height - 1; + if (_width > _height) + MaxXY = _height - 1; else - MaxXY = m_Width - 1; + MaxXY = _width - 1; if (! FullHeight) MaxXY /= 2; - for (y=1; y<=MaxXY; ++y) - { + for (y=1; y<=MaxXY; ++y) { for (x=0; x m_Height) - MaxXY = m_Height - 1; + if (_width > _height) + MaxXY = _height - 1; else - MaxXY = m_Width - 1; + MaxXY = _width - 1; if (! FullHeight) MaxXY /= 2; - for (y=0,xx=MaxXY; y=0; --x,++yy) m_LED[mXY(xx, yy)] = m_LED[mXY(x, y)]; } } - -void cLEDMatrixBase::QuadrantTopTriangleMirror() -{ +void cLEDMatrixBase::QuadrantTopTriangleMirror() { TriangleTopMirror(false); QuadrantMirror(); } - -void cLEDMatrixBase::QuadrantBottomTriangleMirror() -{ +void cLEDMatrixBase::QuadrantBottomTriangleMirror() { TriangleBottomMirror(false); QuadrantMirror(); } +void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) { + drawLine(x0, y0, x1, y1, color); +} + +void cLEDMatrixBase::DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) { + drawRect(x0, y0, (x1-x0), (y1-y0), color); +} -void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) -{ - int16_t dx = x1 - x0; - int16_t dy = y1 - y0; - if (abs(dx) >= abs(dy)) - { - int32_t f = ((int32_t)dy << 16) / (int32_t)abs(dx); - int32_t y = ((int32_t)y0 << 16) + 32768; - if (dx >= 0) - { - for (; x0<=x1; ++x0,y+=f) - (*this)(x0, (y >> 16)) = Col; - } - else - { - for (; x0>=x1; --x0,y+=f) - (*this)(x0, (y >> 16)) = Col; - } - } - else - { - int32_t f = ((int32_t)dx << 16) / (int32_t)abs(dy); - int32_t x = ((int32_t)x0 << 16) + 32768; - if (dy >= 0) - { - for (; y0<=y1; ++y0,x+=f) - (*this)((x >> 16), y0) = Col; - } - else - { - for (; y0>=y1; --y0,x+=f) - (*this)((x >> 16), y0) = Col; - } - } +void cLEDMatrixBase::DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color) { + drawCircle(xc, yc, r, color); } +void cLEDMatrixBase::DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) { + fillRect(x0, y0, (x1-x0), (y1-y0), color); +} -void cLEDMatrixBase::DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) -{ - DrawLine(x0, y0, x0, y1, Col); - DrawLine(x0, y1, x1, y1, Col); - DrawLine(x1, y1, x1, y0, Col); - DrawLine(x1, y0, x0, y0, Col); -} - - -void cLEDMatrixBase::DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col) -{ - int16_t x = -r; - int16_t y = 0; - int16_t e = 2 - (2 * r); - do - { - (*this)(xc + x, yc - y) = Col; - (*this)(xc - x, yc + y) = Col; - (*this)(xc + y, yc + x) = Col; - (*this)(xc - y, yc - x) = Col; - int16_t _e = e; - if (_e <= y) - e += (++y * 2) + 1; - if ((_e > x) || (e > y)) - e += (++x * 2) + 1; - } - while (x < 0); -} - - -void cLEDMatrixBase::DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) -{ - int16_t y = min(y0, y1); - for (int16_t c=abs(y1-y0); c>=0; --c,++y) - DrawLine(x0, y, x1, y, Col); -} - - -void cLEDMatrixBase::DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col) -{ - int16_t x = r; - int16_t y = 0; - int16_t e = 1 - x; - while (x >= y) - { - DrawLine(xc + x, yc + y, xc - x, yc + y, Col); - DrawLine(xc + y, yc + x, xc - y, yc + x, Col); - DrawLine(xc - x, yc - y, xc + x, yc - y, Col); - DrawLine(xc - y, yc - x, xc + y, yc - x, Col); - ++y; - if (e >= 0) - { - --x; - e += 2 * ((y - x) + 1); - } - else - e += (2 * y) + 1; - } +void cLEDMatrixBase::DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color) { + fillCircle(xc, yc, r, color); +} + +void cLEDMatrixBase::drawPixel(int n, CRGB color) { + (*this)(n) = color; +} + +void cLEDMatrixBase::drawPixel(int16_t x, int16_t y, CRGB color) { + (*this)(x,y) = color; +} + +struct CRGB& cLEDMatrixBase::pixel(int n) { + return (*this)(n); +} + +struct CRGB& cLEDMatrixBase::pixel(int16_t x, int16_t y) { + return (*this)(x, y); +} + +void cLEDMatrixBase::fillScreen(CRGB color) { + uint16_t i, n; + uint32_t c; + + n = Size(); + for(i=0; i. + -------------------------------------------------------------------- + LEDMatrix V4 class by Aaron Liddiment (c) 2015 + Inspiration for some of the Matrix functions from Stefan Petrick + FastLED v3.1 library by Daniel Garcia and Mark Kriegsmann. + Written & tested on a Teensy 3.1 using Arduino V1.6.3 & teensyduino V1.22 + --------------------------------------------------------------------*/ - struct CRGB *operator[](int n); - struct CRGB &operator()(int16_t x, int16_t y); - struct CRGB &operator()(int16_t i); +#ifndef _LEDMATRIX_H_ +#define _LEDMATRIX_H_ - int Size() { return(m_Width * m_Height); } - int Width() { return(m_Width); } - int Height() { return(m_Height); } +#if ARDUINO >= 100 + #include +#else + #include + #include +#endif +#include + +// Matrix layout information is passed in the 'matrixType' parameter for +// each constructor. + +// These define the layout for a single 'unified' matrix (e.g. one made +// from NeoPixel strips, or a single NeoPixel shield), or for the pixels +// within each matrix of a tiled display (e.g. multiple NeoPixel shields). +#define MTX_MATRIX_TOP 0x00 // Pixel 0 is at top of matrix +#define MTX_MATRIX_BOTTOM 0x01 // Pixel 0 is at bottom of matrix +#define MTX_MATRIX_LEFT 0x00 // Pixel 0 is at left of matrix +#define MTX_MATRIX_RIGHT 0x02 // Pixel 0 is at right of matrix +#define MTX_MATRIX_CORNER 0x03 // Bitmask for pixel 0 matrix corner +#define MTX_MATRIX_ROWS 0x00 // Matrix is row major (horizontal) +#define MTX_MATRIX_COLUMNS 0x04 // Matrix is column major (vertical) +#define MTX_MATRIX_AXIS 0x04 // Bitmask for row/column layout +#define MTX_MATRIX_PROGRESSIVE 0x00 // Same pixel order across each line +#define MTX_MATRIX_ZIGZAG 0x08 // Pixel order reverses between lines +#define MTX_MATRIX_SEQUENCE 0x08 // Bitmask for pixel line order + +// These apply only to tiled displays (multiple matrices): +#define MTX_TILE_TOP 0x00 // First tile is at top of matrix +#define MTX_TILE_BOTTOM 0x10 // First tile is at bottom of matrix +#define MTX_TILE_LEFT 0x00 // First tile is at left of matrix +#define MTX_TILE_RIGHT 0x20 // First tile is at right of matrix +#define MTX_TILE_CORNER 0x30 // Bitmask for first tile corner +#define MTX_TILE_ROWS 0x00 // Tiles ordered in rows +#define MTX_TILE_COLUMNS 0x40 // Tiles ordered in columns +#define MTX_TILE_AXIS 0x40 // Bitmask for tile H/V orientation +#define MTX_TILE_PROGRESSIVE 0x00 // Same tile order across each line +#define MTX_TILE_ZIGZAG 0x80 // Tile order reverses between lines +#define MTX_TILE_SEQUENCE 0x80 // Bitmask for tile line order + +class cLEDMatrixBase: public FastLED_GFX { +friend class cSprite; + +protected: + struct CRGB *m_LED; + struct CRGB m_OutOfBounds; + uint8_t type; + uint8_t matrixWidth; + uint8_t matrixHeight; + uint8_t tilesX; + uint8_t tilesY; + uint16_t (*remapFn)(uint16_t x, uint16_t y); + +public: + cLEDMatrixBase(int w, int h); - 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(); + virtual uint16_t mXY(uint16_t x, uint16_t y); + void SetLEDArray(struct CRGB *pLED); // Only used with externally defined LED arrays - void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); - void DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); - void DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col); - void DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); - void DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col); + struct CRGB *operator[](int n); + struct CRGB &operator()(int16_t x, int16_t y); + struct CRGB &operator()(int16_t i); + + int Size() { return(_width * _height); } + int Width() { return(_width); } + int Height() { return(_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)); }; -template class cLEDMatrix : public cLEDMatrixBase -{ - private: - static const int16_t m_absWidth = (tWidth * ((tWidth < 0) * -1 + (tWidth > 0))); - static const int16_t m_absHeight = (tHeight * ((tHeight < 0) * -1 + (tHeight > 0))); - struct CRGB p_LED[(m_absWidth * m_absHeight * ((tXMult == 0) && (tXMult == 0))) + ((tXMult != 0) && (tXMult != 0))]; // Will always be at least 1 +template class cLEDMatrix : public cLEDMatrixBase { +private: + static const int m_absWidth = (matrixW * (tX >0?tX:1)); + static const int m_absHeight = (matrixH * (tY >0?tY:1)); + struct CRGB p_LED[(m_absWidth * m_absHeight)]; +public: + cLEDMatrix() + : cLEDMatrixBase(m_absWidth, m_absHeight) { + type = matrixType; + matrixWidth = matrixW; + matrixHeight = matrixH; + tilesX = tX; + tilesY = tY; + remapFn = NULL; + m_LED = p_LED; + } + void SetLEDArray(struct CRGB *pLED) { + m_LED = pLED; + } - public: - cLEDMatrix() - { - m_Width = m_absWidth; - m_Height = m_absHeight; - m_Type = tMType; - if ((tXMult == 0) && (tYMult == 0)) - m_LED = p_LED; - else - m_LED = NULL; - } - void SetLEDArray(struct CRGB *pLED) - { - m_LED = pLED; - } - virtual uint16_t mXY(uint16_t x, uint16_t y) - { - if (tWidth < 0) - x = (m_absWidth - 1) - x; - if (tHeight < 0) - y = (m_absHeight - 1) - y; - if (tMType == HORIZONTAL_MATRIX) - { - if ((tXMult == 0) && (tYMult == 0)) - return((y * m_absWidth) + x); + void ShiftLeft(void) { + /* t.b.d. + switch (tMType) { + case HORIZONTAL_MATRIX: + if (tWidth > 0) + HPWSL(); else - return((y * m_absWidth * tYMult) + (x * tXMult)); - } - else if (tMType == VERTICAL_MATRIX) - { - if ((tXMult == 0) && (tYMult == 0)) - return((x * m_absHeight) + y); + HNWSL(); + break; + case VERTICAL_MATRIX: + if (tWidth > 0) + VPWSL(); else - return((x * m_absHeight * tXMult) + (y * tYMult)); - } - else if (tMType == HORIZONTAL_ZIGZAG_MATRIX) - { - if (y % 2) - { - if ((tXMult == 0) && (tYMult == 0)) - return((((y + 1) * m_absWidth) - 1) - x); - else - return((((y + 1) * m_absWidth * tYMult) - tXMult) - (x * tXMult)); - } + VNWSL(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tWidth > 0) + HZPWSL(); else - { - if ((tXMult == 0) && (tYMult == 0)) - return((y * m_absWidth) + x); - else - return((y * m_absWidth * tYMult) + (x * tXMult)); - } - } - else /* if (tMType == VERTICAL_ZIGZAG_MATRIX) */ - { - if (x % 2) - { - if ((tXMult == 0) && (tYMult == 0)) - return((((x + 1) * m_absHeight) - 1) - y); - else - return((((x + 1) * m_absHeight * tXMult) - tYMult) - (y * tYMult)); - } + HZNWSL(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tWidth > 0) + VZPWSL(); else - { - if ((tXMult == 0) && (tYMult == 0)) - return((x * m_absHeight) + y); - else - return((x * m_absHeight * tXMult) + (y * tYMult)); - } - } + VZNWSL(); + break; } + */ + } - void ShiftLeft(void) - { - if ((tXMult == 0) && (tYMult == 0)) - { - switch (tMType) - { - case HORIZONTAL_MATRIX: - if (tWidth > 0) - HPWSL(); - else - HNWSL(); - break; - case VERTICAL_MATRIX: - if (tWidth > 0) - VPWSL(); - else - VNWSL(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tWidth > 0) - HZPWSL(); - else - HZNWSL(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tWidth > 0) - VZPWSL(); - else - VZNWSL(); - break; - } - } + void ShiftRight(void) { + /* + switch (tMType) { + case HORIZONTAL_MATRIX: + if (tWidth > 0) + HNWSL(); + else + HPWSL(); + break; + case VERTICAL_MATRIX: + if (tWidth > 0) + VNWSL(); + else + VPWSL(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tWidth > 0) + HZNWSL(); + else + HZPWSL(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tWidth > 0) + VZNWSL(); + else + VZPWSL(); + break; } + */ + } - void ShiftRight(void) - { - if ((tXMult == 0) && (tYMult == 0)) - { - switch (tMType) - { - case HORIZONTAL_MATRIX: - if (tWidth > 0) - HNWSL(); - else - HPWSL(); - break; - case VERTICAL_MATRIX: - if (tWidth > 0) - VNWSL(); - else - VPWSL(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tWidth > 0) - HZNWSL(); - else - HZPWSL(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tWidth > 0) - VZNWSL(); - else - VZPWSL(); - break; - } - } + void ShiftDown(void) { + /* + switch (tMType) { + case HORIZONTAL_MATRIX: + if (tHeight > 0) + HPHSD(); + else + HNHSD(); + break; + case VERTICAL_MATRIX: + if (tHeight > 0) + VPHSD(); + else + VNHSD(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tHeight > 0) + HZPHSD(); + else + HZNHSD(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tHeight > 0) + VZPHSD(); + else + VZNHSD(); + break; } + */ + } - void ShiftDown(void) + void ShiftUp(void) { + /* + switch (tMType) { - if ((tXMult == 0) && (tYMult == 0)) - { - switch (tMType) - { - case HORIZONTAL_MATRIX: - if (tHeight > 0) - HPHSD(); - else - HNHSD(); - break; - case VERTICAL_MATRIX: - if (tHeight > 0) - VPHSD(); - else - VNHSD(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tHeight > 0) - HZPHSD(); - else - HZNHSD(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tHeight > 0) - VZPHSD(); - else - VZNHSD(); - break; - } - } + case HORIZONTAL_MATRIX: + if (tHeight > 0) + HNHSD(); + else + HPHSD(); + break; + case VERTICAL_MATRIX: + if (tHeight > 0) + VNHSD(); + else + VPHSD(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tHeight > 0) + HZNHSD(); + else + HZPHSD(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tHeight > 0) + VZNHSD(); + else + VZPHSD(); + break; } + */ + } - void ShiftUp(void) - { - if ((tXMult == 0) && (tYMult == 0)) - { - switch (tMType) - { - case HORIZONTAL_MATRIX: - if (tHeight > 0) - HNHSD(); - else - HPHSD(); - break; - case VERTICAL_MATRIX: - if (tHeight > 0) - VNHSD(); - else - VPHSD(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tHeight > 0) - HZNHSD(); - else - HZPHSD(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tHeight > 0) - VZNHSD(); - else - VZPHSD(); - break; - } - } +private: + // Functions used by ShiftLeft & ShiftRight + void HPWSL(void) { + int16_t i = 0; + for (int16_t y=m_absHeight; y>0; --y,++i) { + for (int16_t x=m_absWidth-1; x>0; --x,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); } - - private: - // Functions used by ShiftLeft & ShiftRight - void HPWSL(void) - { - int16_t i = 0; - for (int16_t y=m_absHeight; y>0; --y,++i) - { - for (int16_t x=m_absWidth-1; x>0; --x,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); - } + } + void HNWSL(void) { + int16_t i = m_absWidth - 1; + for (int16_t y=m_absHeight; y>0; --y) { + for (int16_t x=m_absWidth-1; x>0; --x,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += ((m_absWidth * 2) - 1); } - void HNWSL(void) - { - int16_t i = m_absWidth - 1; + } + void VPWSL(void) { + int16_t i = 0; + int16_t j = m_absHeight; + for (int16_t x=m_absWidth-1; x>0; --x) { for (int16_t y=m_absHeight; y>0; --y) - { - for (int16_t x=m_absWidth-1; x>0; --x,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - i += ((m_absWidth * 2) - 1); - } + p_LED[i++] = p_LED[j++]; } - void VPWSL(void) - { - int16_t i = 0; - int16_t j = m_absHeight; - for (int16_t x=m_absWidth-1; x>0; --x) - { - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i++] = p_LED[j++]; - } + for (int16_t y=m_absHeight; y>0; --y) + p_LED[i++] = CRGB(0, 0, 0); + } + void VNWSL(void) { + int16_t i = (m_absHeight * m_absWidth) - 1; + int16_t j = i - m_absHeight; + for (int16_t x=m_absWidth-1; x>0; --x) { for (int16_t y=m_absHeight; y>0; --y) - p_LED[i++] = CRGB(0, 0, 0); + p_LED[i--] = p_LED[j--]; } - void VNWSL(void) - { - int16_t i = (m_absHeight * m_absWidth) - 1; - int16_t j = i - m_absHeight; - for (int16_t x=m_absWidth-1; x>0; --x) - { - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i--] = p_LED[j--]; + for (int16_t y=m_absHeight; y>0; --y) + p_LED[i--] = CRGB(0, 0, 0); + } + void HZPWSL(void) { + int16_t i = 0; + for (int16_t y=m_absHeight; y>0; y-=2) { + for (int16_t x=m_absWidth-1; x>0; --x,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); + i++; + if (y > 1) { + i += (m_absWidth - 1); + for (int16_t x=m_absWidth-1; x>0; --x,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += m_absWidth; } - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i--] = CRGB(0, 0, 0); } - void HZPWSL(void) - { - int16_t i = 0; - for (int16_t y=m_absHeight; y>0; y-=2) - { + } + void HZNWSL(void) { + int16_t i = m_absWidth - 1; + for (int16_t y=m_absHeight; y>0; y-=2) { + for (int16_t x=m_absWidth-1; x>0; --x,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + if (y > 1) { + i += m_absWidth; for (int16_t x=m_absWidth-1; x>0; --x,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); - i++; - if (y > 1) - { - i += (m_absWidth - 1); - for (int16_t x=m_absWidth-1; x>0; --x,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - i += m_absWidth; - } - } - } - void HZNWSL(void) - { - int16_t i = m_absWidth - 1; - for (int16_t y=m_absHeight; y>0; y-=2) - { - for (int16_t x=m_absWidth-1; x>0; --x,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - if (y > 1) - { - i += m_absWidth; - for (int16_t x=m_absWidth-1; x>0; --x,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); - i += m_absWidth; - } + i += m_absWidth; } } - void VZPWSL(void) - { - int16_t i = 0; - int16_t j = (m_absHeight * 2) - 1; - for (int16_t x=m_absWidth-1; x>0; x-=2) - { + } + void VZPWSL(void) { + int16_t i = 0; + int16_t j = (m_absHeight * 2) - 1; + for (int16_t x=m_absWidth-1; x>0; x-=2) { + for (int16_t y=m_absHeight; y>0; --y) + p_LED[i++] = p_LED[j--]; + if (x > 1) { + j += (m_absHeight * 2); for (int16_t y=m_absHeight; y>0; --y) p_LED[i++] = p_LED[j--]; - if (x > 1) - { - j += (m_absHeight * 2); - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i++] = p_LED[j--]; - j += (m_absHeight * 2); - } + j += (m_absHeight * 2); } - for (int16_t y=m_absHeight; y>0; y--) - p_LED[i++] = CRGB(0, 0, 0); } - void VZNWSL(void) - { - int16_t i = (m_absHeight * m_absWidth) - 1; - int16_t j = m_absHeight * (m_absWidth - 2); - for (int16_t x=m_absWidth-1; x>0; x-=2) - { + for (int16_t y=m_absHeight; y>0; y--) + p_LED[i++] = CRGB(0, 0, 0); + } + void VZNWSL(void) { + int16_t i = (m_absHeight * m_absWidth) - 1; + int16_t j = m_absHeight * (m_absWidth - 2); + for (int16_t x=m_absWidth-1; x>0; x-=2) { + for (int16_t y=m_absHeight; y>0; --y) + p_LED[i--] = p_LED[j++]; + if (x > 1) { + j -= (m_absHeight * 2); for (int16_t y=m_absHeight; y>0; --y) p_LED[i--] = p_LED[j++]; - if (x > 1) - { - j -= (m_absHeight * 2); - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i--] = p_LED[j++]; - j -= (m_absHeight * 2); - } + j -= (m_absHeight * 2); } - for (int16_t y=m_absHeight; y>0; y--) - p_LED[i--] = CRGB(0, 0, 0); } + for (int16_t y=m_absHeight; y>0; y--) + p_LED[i--] = CRGB(0, 0, 0); + } - // Functions used by ShiftDown & ShiftUp - void HPHSD(void) - { - int16_t i = 0; - int16_t j = m_absWidth; - for (int16_t y=m_absHeight-1; y>0; --y) - { - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i++] = p_LED[j++]; - } + // Functions used by ShiftDown & ShiftUp + void HPHSD(void) { + int16_t i = 0; + int16_t j = m_absWidth; + for (int16_t y=m_absHeight-1; y>0; --y) { for (int16_t x=m_absWidth; x>0; --x) - p_LED[i++] = CRGB(0, 0, 0); + p_LED[i++] = p_LED[j++]; } - void HNHSD(void) - { - int16_t i = (m_absWidth * m_absHeight) - 1; - int16_t j = i - m_absWidth; - for (int16_t y=m_absHeight-1; y>0; --y) - { - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i--] = p_LED[j--]; - } + for (int16_t x=m_absWidth; x>0; --x) + p_LED[i++] = CRGB(0, 0, 0); + } + void HNHSD(void) { + int16_t i = (m_absWidth * m_absHeight) - 1; + int16_t j = i - m_absWidth; + for (int16_t y=m_absHeight-1; y>0; --y) { for (int16_t x=m_absWidth; x>0; --x) - p_LED[i--] = CRGB(0, 0, 0); + p_LED[i--] = p_LED[j--]; } - void VPHSD(void) - { - int16_t i = 0; - for (int16_t x=m_absWidth; x>0; --x,++i) - { - for (int16_t y=m_absHeight-1; y>0; --y,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); - } + for (int16_t x=m_absWidth; x>0; --x) + p_LED[i--] = CRGB(0, 0, 0); + } + void VPHSD(void) { + int16_t i = 0; + for (int16_t x=m_absWidth; x>0; --x,++i) { + for (int16_t y=m_absHeight-1; y>0; --y,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); } - void VNHSD(void) - { - int16_t i = m_absHeight - 1; - for (int16_t x=m_absWidth; x>0; --x) - { - for (int16_t y=m_absHeight-1; y>0; --y,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - i += ((m_absHeight * 2) - 1); - } + } + void VNHSD(void) { + int16_t i = m_absHeight - 1; + for (int16_t x=m_absWidth; x>0; --x) { + for (int16_t y=m_absHeight-1; y>0; --y,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += ((m_absHeight * 2) - 1); } - void HZPHSD(void) - { - int16_t i = 0; - int16_t j = (m_absWidth * 2) - 1; - for (int16_t y=m_absHeight-1; y>0; y-=2) - { + } + void HZPHSD(void) { + int16_t i = 0; + int16_t j = (m_absWidth * 2) - 1; + for (int16_t y=m_absHeight-1; y>0; y-=2) { + for (int16_t x=m_absWidth; x>0; --x) + p_LED[i++] = p_LED[j--]; + if (y > 1) { + j += (m_absWidth * 2); for (int16_t x=m_absWidth; x>0; --x) p_LED[i++] = p_LED[j--]; - if (y > 1) - { - j += (m_absWidth * 2); - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i++] = p_LED[j--]; - j += (m_absWidth * 2); - } + j += (m_absWidth * 2); } - for (int16_t x=m_absWidth; x>0; x--) - p_LED[i++] = CRGB(0, 0, 0); } - void HZNHSD(void) - { - int16_t i = (m_absWidth * m_absHeight) - 1; - int16_t j = m_absWidth * (m_absHeight - 2); - for (int16_t y=m_absHeight-1; y>0; y-=2) - { + for (int16_t x=m_absWidth; x>0; x--) + p_LED[i++] = CRGB(0, 0, 0); + } + void HZNHSD(void) { + int16_t i = (m_absWidth * m_absHeight) - 1; + int16_t j = m_absWidth * (m_absHeight - 2); + for (int16_t y=m_absHeight-1; y>0; y-=2) { + for (int16_t x=m_absWidth; x>0; --x) + p_LED[i--] = p_LED[j++]; + if (y > 1) { + j -= (m_absWidth * 2); for (int16_t x=m_absWidth; x>0; --x) p_LED[i--] = p_LED[j++]; - if (y > 1) - { - j -= (m_absWidth * 2); - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i--] = p_LED[j++]; - j -= (m_absWidth * 2); - } + j -= (m_absWidth * 2); } - for (int16_t x=m_absWidth; x>0; x--) - p_LED[i--] = CRGB(0, 0, 0); } - void VZPHSD(void) - { - int16_t i = 0; - for (int16_t x=m_absWidth; x>0; x-=2) - { - for (int16_t y=m_absHeight-1; y>0; --y,++i) - p_LED[i] = p_LED[i + 1]; + for (int16_t x=m_absWidth; x>0; x--) + p_LED[i--] = CRGB(0, 0, 0); + } + void VZPHSD(void) { + int16_t i = 0; + for (int16_t x=m_absWidth; x>0; x-=2) { + for (int16_t y=m_absHeight-1; y>0; --y,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); + i++; + if (x > 1) { + i += (m_absHeight - 1); + for (int16_t y=m_absHeight-1; y>0; --y,--i) + p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); - i++; - if (x > 1) - { - i += (m_absHeight - 1); - for (int16_t y=m_absHeight-1; y>0; --y,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - i += m_absHeight; - } + i += m_absHeight; } } - void VZNHSD(void) - { - int16_t i = m_absHeight - 1; - for (int16_t x=m_absWidth; x>0; x-=2) - { - for (int16_t y=m_absHeight-1; y>0; --y,--i) - p_LED[i] = p_LED[i - 1]; + } + void VZNHSD(void) { + int16_t i = m_absHeight - 1; + for (int16_t x=m_absWidth; x>0; x-=2) { + for (int16_t y=m_absHeight-1; y>0; --y,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + if (x > 1) { + i += m_absHeight; + for (int16_t y=m_absHeight-1; y>0; --y,++i) + p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); - if (x > 1) - { - i += m_absHeight; - for (int16_t y=m_absHeight-1; y>0; --y,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); - i += m_absHeight; - } + i += m_absHeight; } } - + } }; -#endif +#endif // _LEDMATRIX_H_ diff --git a/README.md b/README.md index 2580dff..69f83e4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,244 @@ + +# LEDMatrix +--------------------------- +FastLED port of ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) and simple merge with ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) + Once you have downloaded the Zip file, it should be extracted into your Arduino Libraries folder and the folder renamed to "LEDMatrix". For full instructions see the Wiki icon on the right. + + + + + + + + + +
+ The LEDMatrix library based on Adafruit-NeoMatrix and cLEDMatrix 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](examples/matrixtest/matrixtest.ino)) +---------------------------------------------------------------- +### Parameters +| Parameter | Description | +| ------------ |---------------------------------------------| +| Parameter 1 | width of matrix | +| Parameter 2 | height of matrix | +| Parameter 3 | matrix layout flags, add together as needed | + +### Includes +```c +#include +#include +#include +``` + +### Decleration +```c +// 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; +``` + +### Initialize FastLED +```c +void setup() { + // initial FastLED by using CRGB led source from our matrix class + FastLED.addLeds(matrix[0], matrix.Size()); + FastLED.setBrightness(127); + FastLED.clear(true); +} +``` + + +## Tile Matrix ([Example](examples/tiletest/tiletest.ino)) +---------------------------------------------------------------- +### 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 +```c +#include +#include +#include +``` + +### Decleration +```c +// 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; +``` + +### Initialize FastLED +```c +void setup() { + // initial FastLED by using CRGB led source from our matrix class + FastLED.addLeds(matrix[0], matrix.Size()); + FastLED.setBrightness(127); + FastLED.clear(true); +} +``` + +### Initialize FastLED (multiple controller) +```c +void setup() { + // initial FastLED with multiple controller, by using CRGB led source from each matrix panal + // panel 1 (from 0 to 255) + FastLED.addLeds(matrix[0], 0, MATRIX_SIZE); + // panel 2 (from 255 to 511) + FastLED.addLeds(matrix[0], 1*MATRIX_SIZE, MATRIX_SIZE); + // panel 3 (from 512 to 767) + FastLED.addLeds(matrix[0], 2*MATRIX_SIZE, MATRIX_SIZE); + // panel 4 (from 768 to 1023) + FastLED.addLeds(matrix[0], 3*MATRIX_SIZE, MATRIX_SIZE); + FastLED.setBrightness(127); + FastLED.clear(true); +} +``` + +## Available Methods +```c +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](https://github.com/Jorgen-VikingGod/FastLED-GFX)) +---------------------------------------------------------------- +Simple FastLED port of ([Adafruit-GFX-Library](https://github.com/adafruit/Adafruit-GFX-Library)) + +### Available Methods +```c +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 +``` diff --git a/examples/MatrixExample1/MatrixExample1.ino b/examples/MatrixExample1/MatrixExample1.ino index 4cb0fc1..f486134 100644 --- a/examples/MatrixExample1/MatrixExample1.ino +++ b/examples/MatrixExample1/MatrixExample1.ino @@ -1,5 +1,5 @@ #include - +#include // https://github.com/Jorgen-VikingGod/FastLED-GFX #include // Change the next 6 defines to match your matrix type and size @@ -10,7 +10,7 @@ #define MATRIX_WIDTH 80 // Set this negative if physical led 0 is opposite to where you want logical 0 #define MATRIX_HEIGHT 10 // Set this negative if physical led 0 is opposite to where you want logical 0 -#define MATRIX_TYPE HORIZONTAL_MATRIX // See top of LEDMatrix.h for matrix wiring types +#define MATRIX_TYPE (MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG) // See top of LEDMatrix.h for matrix wiring types cLEDMatrix leds; @@ -44,7 +44,7 @@ void loop() uint8_t h; FastLED.clear(); - + h = hue; if (counter < 1125) { @@ -92,4 +92,3 @@ void loop() counter = 0; FastLED.show(); } - diff --git a/examples/MatrixExample2/MatrixExample2.ino b/examples/MatrixExample2/MatrixExample2.ino index 14d0793..674e92a 100644 --- a/examples/MatrixExample2/MatrixExample2.ino +++ b/examples/MatrixExample2/MatrixExample2.ino @@ -1,5 +1,5 @@ #include - +#include // https://github.com/Jorgen-VikingGod/FastLED-GFX #include // Change the next 6 defines to match your matrix type and size @@ -10,7 +10,7 @@ #define MATRIX_WIDTH 80 // Set this negative if physical led 0 is opposite to where you want logical 0 #define MATRIX_HEIGHT 10 // Set this negative if physical led 0 is opposite to where you want logical 0 -#define MATRIX_TYPE HORIZONTAL_MATRIX // See top of LEDMatrix.h for matrix wiring types +#define MATRIX_TYPE (MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG) // See top of LEDMatrix.h for matrix wiring types cLEDMatrix leds; @@ -83,4 +83,3 @@ void loop() FastLED.show(); delay(20); } - diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino new file mode 100644 index 0000000..8c70273 --- /dev/null +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -0,0 +1,122 @@ +#include +#include // https://github.com/Jorgen-VikingGod/FastLED-GFX +#include + +// Change the next 6 defines to match your matrix type and size + +#define LED_PIN 2 +#define COLOR_ORDER GRB +#define CHIPSET WS2812B + +#define MATRIX_TILE_WIDTH 16 // width of each matrix (not total display) +#define MATRIX_TILE_HEIGHT 16 // height of each matrix +#define NUM_H_TILES 4 // number of matrices arranged horizontally +#define NUM_V_TILES 1 // number of matrices arranged vertically +#define MATRIX_LAYOUT MTX_TILE_TOP + MTX_TILE_LEFT + MTX_TILE_ROWS + MTX_TILE_PROGRESSIVE + + MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG; + +// MATRIX DECLARATION: +// Parameter 1 = width of each matrix (not total display) +// Parameter 2 = height of each matrix +// Parameter 3 = matrix layout flags, add together as needed: +// MTX_MATRIX_TOP, MTX_MATRIX_BOTTOM, MTX_MATRIX_LEFT, MTX_MATRIX_RIGHT: +// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g. +// MTX_MATRIX_TOP + MTX_MATRIX_LEFT for the top-left corner. +// MTX_MATRIX_ROWS, MTX_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are +// arranged in horizontal rows or in vertical columns, respectively; +// pick one or the other. +// MTX_MATRIX_PROGRESSIVE, MTX_MATRIX_ZIGZAG: all rows/columns WITHIN +// EACH MATRIX proceed in the same order, or alternate lines reverse +// direction; pick one. +// MTX_TILE_TOP, MTX_TILE_BOTTOM, MTX_TILE_LEFT, MTX_TILE_RIGHT: +// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick +// two, e.g. MTX_TILE_TOP + MTX_TILE_LEFT for the top-left corner. +// MTX_TILE_ROWS, MTX_TILE_COLUMNS: the matrices in the OVERALL DISPLAY +// are arranged in horizontal rows or in vertical columns, respectively; +// pick one or the other. +// MTX_TILE_PROGRESSIVE, MTX_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES +// (tiles) in the OVERALL DISPLAY proceed in the same order for every +// line, or alternate lines reverse direction; pick one. When using +// zig-zag order, the orientation of the matrices in alternate rows +// will be rotated 180 degrees (this is normal -- simplifies wiring). +// Parameter 4 = number of matrices arranged horizontally +// Parameter 5 = number of matrices arranged vertically +// See example below for these values in action. + +// Example with four 16x16 matrices. In this application we'd +// like to arrange the four matrices side-by-side in a wide display. +// The first matrix (tile) will be at the left, and the first pixel within +// that matrix is at the top left. The matrices use zig-zag line ordering. +// There's only one row here, so it doesn't matter if we declare it in row +// or column order. +cLEDMatrix leds; + +uint8_t angle = 0; + +void setup() +{ + FastLED.addLeds(leds[0], leds.Size()); + FastLED.setBrightness(127); + FastLED.clear(true); + delay(500); + FastLED.showColor(CRGB::Red); + delay(1000); + FastLED.showColor(CRGB::Lime); + delay(1000); + FastLED.showColor(CRGB::Blue); + delay(1000); + FastLED.showColor(CRGB::White); + delay(1000); + FastLED.clear(true); + + // Scottish Flag + leds.DrawFilledRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(0, 0, 255)); + leds.DrawRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); + leds.DrawLine(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); + leds.DrawLine(0, 1, leds.Width() - 1, leds.Height() - 2, CRGB(255, 255, 255)); + leds.DrawLine(0, leds.Height() - 1, leds.Width() - 1, 0, CRGB(255, 255, 255)); + leds.DrawLine(0, leds.Height() - 2, leds.Width() - 1, 1, CRGB(255, 255, 255)); + FastLED.show(); + delay(5000); + + // Japanese Flag + leds.DrawFilledRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); + uint16_t r = min((leds.Width() - 1) / 2, (leds.Height() - 1) / 2) - 1; + leds.DrawFilledCircle((leds.Width() - 1) / 2, (leds.Height() - 1) / 2, r, CRGB(255, 0, 0)); + FastLED.show(); + delay(5000); + + // Norwegian Flag + int16_t x = (leds.Width() / 4); + int16_t y = (leds.Height() / 2) - 2; + leds.DrawFilledRectangle(0, 0, x, y, CRGB(255, 255, 255)); + leds.DrawFilledRectangle(0, 0, x - 1, y - 1, CRGB(255, 0, 0)); + leds.DrawFilledRectangle(x + 3, 0, leds.Width() - 1, y, CRGB(255, 255, 255)); + leds.DrawFilledRectangle(x + 4, 0, leds.Width() - 1, y - 1, CRGB(255, 0, 0)); + leds.DrawFilledRectangle(0, y + 3, x, leds.Height() - 1, CRGB(255, 255, 255)); + leds.DrawFilledRectangle(0, y + 4, x - 1, leds.Height() - 1, CRGB(255, 0, 0)); + leds.DrawFilledRectangle(x + 3, y + 3, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); + leds.DrawFilledRectangle(x + 4, y + 4, leds.Width() - 1, leds.Height() - 1, CRGB(255, 0, 0)); + leds.DrawLine(0, y + 1, leds.Width() - 1, y + 1, CRGB(0, 0, 255)); + leds.DrawLine(0, y + 2, leds.Width() - 1, y + 2, CRGB(0, 0, 255)); + leds.DrawLine(x + 1, 0, x + 1, leds.Height() - 1, CRGB(0, 0, 255)); + leds.DrawLine(x + 2, 0, x + 2, leds.Height() - 1, CRGB(0, 0, 255)); + FastLED.show(); + delay(5000); + leds.ShiftLeft(); +} + + +void loop() +{ + uint8_t h = sin8(angle); + leds.ShiftLeft(); + for (int16_t y=leds.Height()-1; y>=0; --y) + { + leds(leds.Width()-1, y) = CHSV(h, 255, 255); + h += 32; + } + angle += 4; + FastLED.show(); + delay(20); +} From ccc3ba771f3d556f1e9dd7a3eadf2f4a227cfbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 29 Apr 2016 17:17:28 +0200 Subject: [PATCH 02/35] add new examples --- examples/matrixtest/matrixtest.ino | 76 ++++++++++++++++++++ examples/tiletest/tiletest.ino | 111 +++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 examples/matrixtest/matrixtest.ino create mode 100644 examples/tiletest/tiletest.ino diff --git a/examples/matrixtest/matrixtest.ino b/examples/matrixtest/matrixtest.ino new file mode 100644 index 0000000..f36357f --- /dev/null +++ b/examples/matrixtest/matrixtest.ino @@ -0,0 +1,76 @@ +// Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix +// replace internal use of NeoPixel library with CRGB array to use with FastLED +// +// modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) +// date: 2016/04/27 +// -------------------------------------------------------------------- +// Original copyright & description below +// -------------------------------------------------------------------- +// Adafruit_NeoMatrix example for single NeoPixel Shield. +// Scrolls 'Howdy' across the matrix in a portrait (vertical) orientation. + +#include +#include +#include + +#define LED_PIN 2 +#define COLOR_ORDER GRB +#define CHIPSET WS2812B + +#define MATRIX_WIDTH 5 // width of FastLED 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 + +// MATRIX DECLARATION: +// Parameter 1 = width of FastLED matrix +// Parameter 2 = height of matrix +// Parameter 3 = matrix layout flags, add together as needed: +// MTX_MATRIX_TOP, MTX_MATRIX_BOTTOM, MTX_MATRIX_LEFT, MTX_MATRIX_RIGHT: +// Position of the FIRST LED in the matrix; pick two, e.g. +// MTX_MATRIX_TOP + MTX_MATRIX_LEFT for the top-left corner. +// MTX_MATRIX_ROWS, MTX_MATRIX_COLUMNS: LEDs are arranged in horizontal +// rows or in vertical columns, respectively; pick one or the other. +// MTX_MATRIX_PROGRESSIVE, MTX_MATRIX_ZIGZAG: all rows/columns proceed +// in the same order, or alternate lines reverse direction; pick one. +// See example below for these values in action. + + +// Example for NeoPixel Shield. In this application we'd like to use it +// as a 5x8 tall matrix, with the USB port positioned at the top of the +// Arduino. When held that way, the first pixel is at the top right, and +// lines are arranged in columns, progressive order. + +cFastLEDMatrix matrix; + +const CRGB colors[] = { + CRGB(255, 0, 0), + CRGB(0, 255, 0), + CRGB(0, 0, 255) +}; + +void setup() { + // initial FastLED + FastLED.addLeds(matrix[0], matrix.Size()); + FastLED.setBrightness(127); + FastLED.clear(true); + + matrix.setTextWrap(false); + matrix.setBrightness(40); + matrix.setTextColor(colors[0]); +} + +int x = matrix.width(); +int pass = 0; + +void loop() { + matrix.fillScreen(0); + matrix.setCursor(x, 0); + matrix.print(F("Howdy")); + if(--x < -36) { + x = matrix.width(); + if(++pass >= 3) pass = 0; + matrix.setTextColor(colors[pass]); + } + FastLED.show(); + delay(100); +} diff --git a/examples/tiletest/tiletest.ino b/examples/tiletest/tiletest.ino new file mode 100644 index 0000000..8e198c7 --- /dev/null +++ b/examples/tiletest/tiletest.ino @@ -0,0 +1,111 @@ +// Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix +// replace internal use of NeoPixel library with CRGB array to use with FastLED +// +// modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) +// date: 2016/04/27 +// -------------------------------------------------------------------- +// Original copyright & description below +// -------------------------------------------------------------------- +// Adafruit_NeoMatrix example for tiled NeoPixel matrices. Scrolls +// 'Howdy' across three 10x8 NeoPixel grids that were created using +// NeoPixel 60 LEDs per meter flex strip. + +#include +#include +#include + +#define LED_PIN 2 +#define COLOR_ORDER GRB +#define CHIPSET WS2812B + +#define TARGET_FRAME_TIME 25 // Desired update rate, though if too many leds it will just run as fast as it can! +#define PLASMA_X_FACTOR 24 +#define PLASMA_Y_FACTOR 24 + +// MATRIX DECLARATION: +// 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: +// MTX_MATRIX_TOP, MTX_MATRIX_BOTTOM, MTX_MATRIX_LEFT, MTX_MATRIX_RIGHT: +// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g. +// MTX_MATRIX_TOP + MTX_MATRIX_LEFT for the top-left corner. +// MTX_MATRIX_ROWS, MTX_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are +// arranged in horizontal rows or in vertical columns, respectively; +// pick one or the other. +// MTX_MATRIX_PROGRESSIVE, MTX_MATRIX_ZIGZAG: all rows/columns WITHIN +// EACH MATRIX proceed in the same order, or alternate lines reverse +// direction; pick one. +// MTX_TILE_TOP, MTX_TILE_BOTTOM, MTX_TILE_LEFT, MTX_TILE_RIGHT: +// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick +// two, e.g. MTX_TILE_TOP + MTX_TILE_LEFT for the top-left corner. +// MTX_TILE_ROWS, MTX_TILE_COLUMNS: the matrices in the OVERALL DISPLAY +// are arranged in horizontal rows or in vertical columns, respectively; +// pick one or the other. +// MTX_TILE_PROGRESSIVE, MTX_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES +// (tiles) in the OVERALL DISPLAY proceed in the same order for every +// line, or alternate lines reverse direction; pick one. When using +// zig-zag order, the orientation of the matrices in alternate rows +// will be rotated 180 degrees (this is normal -- simplifies wiring). +// Parameter 4 = number of matrices arranged horizontally +// Parameter 5 = number of matrices arranged vertically +// See example below for these values in action. + +// Example with three 10x8 matrices (created using NeoPixel flex strip -- +// these grids are not a ready-made product). In this application we'd +// like to arrange the three matrices side-by-side in a wide display. +// The first matrix (tile) will be at the left, and the first pixel within +// that matrix is at the top left. The matrices use zig-zag line ordering. +// There's only one row here, so it doesn't matter if we declare it in row +// or column order. The matrices use 800 KHz (v2) pixels that expect GRB +// color data. + +#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) + +cFastLEDMatrix matrix; + +uint16_t PlasmaTime, PlasmaShift; +uint32_t LoopDelayMS, LastLoop; + +void ESP8266_yield() { +#ifdef ESP8266 + yield(); // secure time for the WiFi stack of ESP8266 +#endif +} + +void setup() { + // initial FastLED + FastLED.addLeds(matrix[0], matrix.Size()); + FastLED.setBrightness(128); + FastLED.clear(true); + // initial helpers for plasma animation + LoopDelayMS = TARGET_FRAME_TIME; + LastLoop = millis() - LoopDelayMS; + PlasmaShift = (random8(0, 5) * 32) + 64; + PlasmaTime = 0; +} + +void loop() { + if (abs(millis() - LastLoop) >= LoopDelayMS) { + LastLoop = millis(); + FastLED.clear(); + // Fill background with dim plasma + for (int16_t x=0; x PlasmaTime) + PlasmaShift = (random8(0, 5) * 32) + 64; + FastLED.show(); + } +} From e545cebd076e7bef8dd313d22c228d5eff0fb554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 29 Apr 2016 17:18:04 +0200 Subject: [PATCH 03/35] typo --- examples/matrixtest/matrixtest.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/matrixtest/matrixtest.ino b/examples/matrixtest/matrixtest.ino index f36357f..d65d120 100644 --- a/examples/matrixtest/matrixtest.ino +++ b/examples/matrixtest/matrixtest.ino @@ -11,7 +11,7 @@ #include #include -#include +#include #define LED_PIN 2 #define COLOR_ORDER GRB From 82bd3e73733cea542fcfdfaefde2870edd4fd3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 29 Apr 2016 17:18:22 +0200 Subject: [PATCH 04/35] typo --- examples/tiletest/tiletest.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tiletest/tiletest.ino b/examples/tiletest/tiletest.ino index 8e198c7..3e3b370 100644 --- a/examples/tiletest/tiletest.ino +++ b/examples/tiletest/tiletest.ino @@ -12,7 +12,7 @@ #include #include -#include +#include #define LED_PIN 2 #define COLOR_ORDER GRB From f1863a00e4c24bc7899cffc6cc0667bb02f6e8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Mon, 2 May 2016 09:31:03 +0200 Subject: [PATCH 05/35] add release and dependencies badge icons --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 69f83e4..82fe262 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ # LEDMatrix ---------------------------- -FastLED port of ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) and simple merge with ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) +------------ +[![GitHub version](https://img.shields.io/github/release/Jorgen-VikingGod/LEDMatrix.svg)](https://github.com/Jorgen-VikingGod/LEDMatrix/releases/tag/v0.1.0) +[![GitHub version](https://img.shields.io/badge/dependencies-FastLED-456789.svg)](https://github.com/FastLED/FastLED) +[![GitHub version](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) -Once you have downloaded the Zip file, it should be extracted into your Arduino Libraries folder and the folder renamed to "LEDMatrix". +> A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and FastLED port of ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) by using the graphics library [FastLED-GFX](https://github.com/Jorgen-VikingGod/FastLED-GFX) (based on [Adafruit-GFX-Library](https://github.com/adafruit/Adafruit-GFX-Library)) -For full instructions see the Wiki icon on the right. +Once you have downloaded the Zip file, it should be extracted into your Arduino Libraries folder and the folder renamed to "LEDMatrix". From 784b4c5ec4e59b23cd16f78e7a1a643cd9240e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Mon, 2 May 2016 09:35:48 +0200 Subject: [PATCH 06/35] version badge --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82fe262..d23793d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LEDMatrix ------------ -[![GitHub version](https://img.shields.io/github/release/Jorgen-VikingGod/LEDMatrix.svg)](https://github.com/Jorgen-VikingGod/LEDMatrix/releases/tag/v0.1.0) -[![GitHub version](https://img.shields.io/badge/dependencies-FastLED-456789.svg)](https://github.com/FastLED/FastLED) +[![GitHub version](https://badge.fury.io/gh/Jorgen-VikingGod%2FLEDMatrix.svg)](https://badge.fury.io/gh/Jorgen-VikingGod%2FLEDMatrix) +[![GitHub version](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) [![GitHub version](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) > A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and FastLED port of ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) by using the graphics library [FastLED-GFX](https://github.com/Jorgen-VikingGod/FastLED-GFX) (based on [Adafruit-GFX-Library](https://github.com/adafruit/Adafruit-GFX-Library)) From 527cbe876c20c780f193d7c50af146ae15e1eeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 06:52:10 +0200 Subject: [PATCH 07/35] add travis script --- travis/common.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 travis/common.sh diff --git a/travis/common.sh b/travis/common.sh new file mode 100644 index 0000000..d115085 --- /dev/null +++ b/travis/common.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +function build_examples() +{ + # track the exit code for this platform + local exit_code=0 + # loop through results and add them to the array + examples=($(find $PWD/examples/ -name "*.pde" -o -name "*.ino")) + + # get the last example in the array + local last="${examples[@]:(-1)}" + + # loop through example sketches + for example in "${examples[@]}"; do + + # store the full path to the example's sketch directory + local example_dir=$(dirname $example) + + # store the filename for the example without the path + local example_file=$(basename $example) + + echo "$example_file: " + local sketch="$example_dir/$example_file" + echo "$sketch" + #arduino -v --verbose-build --verify $sketch + + # verify the example, and save stdout & stderr to a variable + # we have to avoid reading the exit code of local: + # "when declaring a local variable in a function, the local acts as a command in its own right" + local build_stdout + build_stdout=$(arduino --verify $sketch 2>&1) + + # echo output if the build failed + if [ $? -ne 0 ]; then + # heavy X + echo -e "\xe2\x9c\x96" + echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" + echo "$build_stdout" + echo -e "\n------------------------------------------------------------------------\n" + + # mark as fail + exit_code=1 + + else + # heavy checkmark + echo -e "\xe2\x9c\x93" + fi + done + + return $exit_code +} From 12e5930a1c978b36e90b53af92e4ba7954d3f488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 06:56:20 +0200 Subject: [PATCH 08/35] initialize travis file --- .travis.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e4a9998 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +language: c +before_install: + - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" + - sleep 3 + - export DISPLAY=:1.0 + - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz + - tar xf arduino-1.6.5-linux64.tar.xz + - sudo mv arduino-1.6.5 /usr/local/share/arduino + - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino +install: + - ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager +# boards manager not working on 1.6.7 - 1.6.8 + - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs +# install lib arduino json not working in 1.6.5 +# - arduino --install-library "FastLED" + - git clone https://github.com/FastLED/FastLED /usr/local/share/arduino/libraries/FastLED +# - arduino --install-library "FastLED-GFX" + - git clone https://github.com/Jorgen-VikingGod/FastLED-GFX /usr/local/share/arduino/libraries/FastLED-GFX + - arduino --install-boards esp8266:esp8266 + - arduino --board esp8266:esp8266:generic --save-prefs + - arduino --pref "compiler.warning_level=all" --save-prefs +script: + - "echo $PWD" + - "echo $HOME" + - "ls $PWD" + - source $TRAVIS_BUILD_DIR/travis/common.sh + - build_examples +# - "cat $PWD/examples/MatrixExample1/MatrixExample1.ino" +# - arduino -v --verbose-build --verify $PWD/examples/MatrixExample1/MatrixExample1.ino +# - arduino --verify --board arduino:avr:uno $PWD/examples/IncomingCall/IncomingCall.ino +# - arduino --verify --board arduino:avr:uno $PWD/examples/AdafruitIO_GPS/AdafruitIO_GPS.ino +notifications: + email: + on_success: change + on_failure: change From 170eba6264e3b6ac4685c06d8b9b7bf0a3e27f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 06:59:30 +0200 Subject: [PATCH 09/35] typo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e4a9998..a7dc8fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_install: - sudo mv arduino-1.6.5 /usr/local/share/arduino - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino install: - - ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager + - ln -s $PWD /usr/local/share/arduino/libraries/LEDMatrix # boards manager not working on 1.6.7 - 1.6.8 - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs # install lib arduino json not working in 1.6.5 From 0b660d8b2be2940bfc5b20ba78531caa7134b0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:02:22 +0200 Subject: [PATCH 10/35] typo --- examples/tiletest/tiletest.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tiletest/tiletest.ino b/examples/tiletest/tiletest.ino index 3e3b370..c964c56 100644 --- a/examples/tiletest/tiletest.ino +++ b/examples/tiletest/tiletest.ino @@ -66,7 +66,7 @@ #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) -cFastLEDMatrix matrix; +cLEDMatrix matrix; uint16_t PlasmaTime, PlasmaShift; uint32_t LoopDelayMS, LastLoop; From 64f800df9439289a10d4ef6d88f437981fdaae0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:02:49 +0200 Subject: [PATCH 11/35] typo --- examples/matrixtest/matrixtest.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/matrixtest/matrixtest.ino b/examples/matrixtest/matrixtest.ino index d65d120..00d3bad 100644 --- a/examples/matrixtest/matrixtest.ino +++ b/examples/matrixtest/matrixtest.ino @@ -40,7 +40,7 @@ // Arduino. When held that way, the first pixel is at the top right, and // lines are arranged in columns, progressive order. -cFastLEDMatrix matrix; +cLEDMatrix matrix; const CRGB colors[] = { CRGB(255, 0, 0), From 91b92836c39fc01b0c54992949609cfc99c171cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:08:25 +0200 Subject: [PATCH 12/35] typo --- examples/matrixtest/matrixtest.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/matrixtest/matrixtest.ino b/examples/matrixtest/matrixtest.ino index 00d3bad..bb182af 100644 --- a/examples/matrixtest/matrixtest.ino +++ b/examples/matrixtest/matrixtest.ino @@ -55,7 +55,6 @@ void setup() { FastLED.clear(true); matrix.setTextWrap(false); - matrix.setBrightness(40); matrix.setTextColor(colors[0]); } From c6f7ccd5b8e32e540391895e8d67138423ac367f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:10:26 +0200 Subject: [PATCH 13/35] obsolete --- .../MatrixTilesExample/MatrixTilesExample.ino | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 examples/MatrixTilesExample/MatrixTilesExample.ino diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino deleted file mode 100644 index 8c70273..0000000 --- a/examples/MatrixTilesExample/MatrixTilesExample.ino +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include // https://github.com/Jorgen-VikingGod/FastLED-GFX -#include - -// Change the next 6 defines to match your matrix type and size - -#define LED_PIN 2 -#define COLOR_ORDER GRB -#define CHIPSET WS2812B - -#define MATRIX_TILE_WIDTH 16 // width of each matrix (not total display) -#define MATRIX_TILE_HEIGHT 16 // height of each matrix -#define NUM_H_TILES 4 // number of matrices arranged horizontally -#define NUM_V_TILES 1 // number of matrices arranged vertically -#define MATRIX_LAYOUT MTX_TILE_TOP + MTX_TILE_LEFT + MTX_TILE_ROWS + MTX_TILE_PROGRESSIVE + - MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG; - -// MATRIX DECLARATION: -// Parameter 1 = width of each matrix (not total display) -// Parameter 2 = height of each matrix -// Parameter 3 = matrix layout flags, add together as needed: -// MTX_MATRIX_TOP, MTX_MATRIX_BOTTOM, MTX_MATRIX_LEFT, MTX_MATRIX_RIGHT: -// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g. -// MTX_MATRIX_TOP + MTX_MATRIX_LEFT for the top-left corner. -// MTX_MATRIX_ROWS, MTX_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are -// arranged in horizontal rows or in vertical columns, respectively; -// pick one or the other. -// MTX_MATRIX_PROGRESSIVE, MTX_MATRIX_ZIGZAG: all rows/columns WITHIN -// EACH MATRIX proceed in the same order, or alternate lines reverse -// direction; pick one. -// MTX_TILE_TOP, MTX_TILE_BOTTOM, MTX_TILE_LEFT, MTX_TILE_RIGHT: -// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick -// two, e.g. MTX_TILE_TOP + MTX_TILE_LEFT for the top-left corner. -// MTX_TILE_ROWS, MTX_TILE_COLUMNS: the matrices in the OVERALL DISPLAY -// are arranged in horizontal rows or in vertical columns, respectively; -// pick one or the other. -// MTX_TILE_PROGRESSIVE, MTX_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES -// (tiles) in the OVERALL DISPLAY proceed in the same order for every -// line, or alternate lines reverse direction; pick one. When using -// zig-zag order, the orientation of the matrices in alternate rows -// will be rotated 180 degrees (this is normal -- simplifies wiring). -// Parameter 4 = number of matrices arranged horizontally -// Parameter 5 = number of matrices arranged vertically -// See example below for these values in action. - -// Example with four 16x16 matrices. In this application we'd -// like to arrange the four matrices side-by-side in a wide display. -// The first matrix (tile) will be at the left, and the first pixel within -// that matrix is at the top left. The matrices use zig-zag line ordering. -// There's only one row here, so it doesn't matter if we declare it in row -// or column order. -cLEDMatrix leds; - -uint8_t angle = 0; - -void setup() -{ - FastLED.addLeds(leds[0], leds.Size()); - FastLED.setBrightness(127); - FastLED.clear(true); - delay(500); - FastLED.showColor(CRGB::Red); - delay(1000); - FastLED.showColor(CRGB::Lime); - delay(1000); - FastLED.showColor(CRGB::Blue); - delay(1000); - FastLED.showColor(CRGB::White); - delay(1000); - FastLED.clear(true); - - // Scottish Flag - leds.DrawFilledRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(0, 0, 255)); - leds.DrawRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); - leds.DrawLine(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); - leds.DrawLine(0, 1, leds.Width() - 1, leds.Height() - 2, CRGB(255, 255, 255)); - leds.DrawLine(0, leds.Height() - 1, leds.Width() - 1, 0, CRGB(255, 255, 255)); - leds.DrawLine(0, leds.Height() - 2, leds.Width() - 1, 1, CRGB(255, 255, 255)); - FastLED.show(); - delay(5000); - - // Japanese Flag - leds.DrawFilledRectangle(0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); - uint16_t r = min((leds.Width() - 1) / 2, (leds.Height() - 1) / 2) - 1; - leds.DrawFilledCircle((leds.Width() - 1) / 2, (leds.Height() - 1) / 2, r, CRGB(255, 0, 0)); - FastLED.show(); - delay(5000); - - // Norwegian Flag - int16_t x = (leds.Width() / 4); - int16_t y = (leds.Height() / 2) - 2; - leds.DrawFilledRectangle(0, 0, x, y, CRGB(255, 255, 255)); - leds.DrawFilledRectangle(0, 0, x - 1, y - 1, CRGB(255, 0, 0)); - leds.DrawFilledRectangle(x + 3, 0, leds.Width() - 1, y, CRGB(255, 255, 255)); - leds.DrawFilledRectangle(x + 4, 0, leds.Width() - 1, y - 1, CRGB(255, 0, 0)); - leds.DrawFilledRectangle(0, y + 3, x, leds.Height() - 1, CRGB(255, 255, 255)); - leds.DrawFilledRectangle(0, y + 4, x - 1, leds.Height() - 1, CRGB(255, 0, 0)); - leds.DrawFilledRectangle(x + 3, y + 3, leds.Width() - 1, leds.Height() - 1, CRGB(255, 255, 255)); - leds.DrawFilledRectangle(x + 4, y + 4, leds.Width() - 1, leds.Height() - 1, CRGB(255, 0, 0)); - leds.DrawLine(0, y + 1, leds.Width() - 1, y + 1, CRGB(0, 0, 255)); - leds.DrawLine(0, y + 2, leds.Width() - 1, y + 2, CRGB(0, 0, 255)); - leds.DrawLine(x + 1, 0, x + 1, leds.Height() - 1, CRGB(0, 0, 255)); - leds.DrawLine(x + 2, 0, x + 2, leds.Height() - 1, CRGB(0, 0, 255)); - FastLED.show(); - delay(5000); - leds.ShiftLeft(); -} - - -void loop() -{ - uint8_t h = sin8(angle); - leds.ShiftLeft(); - for (int16_t y=leds.Height()-1; y>=0; --y) - { - leds(leds.Width()-1, y) = CHSV(h, 255, 255); - h += 32; - } - angle += 4; - FastLED.show(); - delay(20); -} From 00241f79f06f1d9c37140ce40d60c18ba07791dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:14:00 +0200 Subject: [PATCH 14/35] add travis build badge --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d23793d..75cf7c2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # LEDMatrix ------------ +[![Travis build](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix.svg)](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix) [![GitHub version](https://badge.fury.io/gh/Jorgen-VikingGod%2FLEDMatrix.svg)](https://badge.fury.io/gh/Jorgen-VikingGod%2FLEDMatrix) -[![GitHub version](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) -[![GitHub version](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) +[![FastLED dependencies](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) +[![FastLED-GFX dependencies](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) > A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and FastLED port of ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) by using the graphics library [FastLED-GFX](https://github.com/Jorgen-VikingGod/FastLED-GFX) (based on [Adafruit-GFX-Library](https://github.com/adafruit/Adafruit-GFX-Library)) From 4cfcc4de6f4860eb2d6444466b254a759299cff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:19:48 +0200 Subject: [PATCH 15/35] change verion badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75cf7c2..ff47812 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # LEDMatrix ------------ [![Travis build](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix.svg)](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix) -[![GitHub version](https://badge.fury.io/gh/Jorgen-VikingGod%2FLEDMatrix.svg)](https://badge.fury.io/gh/Jorgen-VikingGod%2FLEDMatrix) +[![GitHub version](https://img.shields.io/github/release/Jorgen-VikingGod/LEDMatrix.svg)](https://github.com/Jorgen-VikingGod/LEDMatrix/releases/latest) [![FastLED dependencies](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) [![FastLED-GFX dependencies](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) From aa0429c2ebb7c075ab82c0e5db58e492557ce7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Tue, 3 May 2016 07:22:06 +0200 Subject: [PATCH 16/35] change travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff47812..941aa5d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LEDMatrix ------------ -[![Travis build](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix.svg)](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix) +[![Travis build](https://img.shields.io/travis/Jorgen-VikingGod/LEDMatrix.svg)](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix) [![GitHub version](https://img.shields.io/github/release/Jorgen-VikingGod/LEDMatrix.svg)](https://github.com/Jorgen-VikingGod/LEDMatrix/releases/latest) [![FastLED dependencies](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) [![FastLED-GFX dependencies](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) From fd59746983c2f0a395563d1ab3ae07040bfb518e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 15:42:51 +0100 Subject: [PATCH 17/35] update to new modifications Aaron helped to update my fork; replaced all the dependencies and make it nice ;) --- LEDMatrix.cpp | 374 +++---- LEDMatrix.h | 951 ++++++++++-------- examples/MatrixExample1/MatrixExample1.ino | 24 +- .../MatrixTilesExample.ino} | 30 +- examples/matrixtest/matrixtest.ino | 75 -- examples/tiletest/tiletest.ino | 111 -- 6 files changed, 733 insertions(+), 832 deletions(-) mode change 100644 => 100755 LEDMatrix.cpp rename examples/{MatrixExample2/MatrixExample2.ino => MatrixTilesExample/MatrixTilesExample.ino} (71%) delete mode 100644 examples/matrixtest/matrixtest.ino delete mode 100644 examples/tiletest/tiletest.ino diff --git a/LEDMatrix.cpp b/LEDMatrix.cpp old mode 100644 new mode 100755 index 1a8eb93..c29655a --- a/LEDMatrix.cpp +++ b/LEDMatrix.cpp @@ -1,204 +1,92 @@ -/*-------------------------------------------------------------------- - Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix - and on https://github.com/AaronLiddiment/LEDMatrix - replace internal use of NeoPixel library with CRGB array to use with FastLED - +/* + LEDMatrix V5 class by Aaron Liddiment (c) 2016 modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) date: 2016/04/27 - -------------------------------------------------------------------- - Original copyright & description below - -------------------------------------------------------------------- - This file is part of the Adafruit NeoMatrix library. - - NeoMatrix is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - NeoMatrix is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with NeoMatrix. If not, see - . - -------------------------------------------------------------------- - LEDMatrix V4 class by Aaron Liddiment (c) 2015 + Inspiration for some of the Matrix functions from Stefan Petrick + FastLED v3.1 library by Daniel Garcia and Mark Kriegsmann. Written & tested on a Teensy 3.1 using Arduino V1.6.3 & teensyduino V1.22 - --------------------------------------------------------------------*/ +*/ + #include #include -#ifdef __AVR__ - #include -#elif defined(ESP8266) - #include -#else - #ifndef pgm_read_byte - #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) - #endif -#endif -#ifndef _swap_uint16_t -#define _swap_uint16_t(a, b) { uint16_t t = a; a = b; b = t; } -#endif - -cLEDMatrixBase::cLEDMatrixBase(int w, int h) - : FastLED_GFX(w, h) { } +cLEDMatrixBase::cLEDMatrixBase() +{ +} -struct CRGB* cLEDMatrixBase::operator[](int n) { +struct CRGB* cLEDMatrixBase::operator[](int n) +{ return(&m_LED[n]); } -struct CRGB& cLEDMatrixBase::operator()(int16_t x, int16_t y) { - if ( (x >= 0) && (x < _width) && (y >= 0) && (y < _height)) +struct CRGB& cLEDMatrixBase::operator()(int16_t x, int16_t y) +{ + if ( (x >= 0) && (x < m_Width) && (y >= 0) && (y < m_Height)) return(m_LED[mXY(x, y)]); else return(m_OutOfBounds); } -struct CRGB& cLEDMatrixBase::operator()(int16_t i) { - if ((i >=0) && (i < (_width * _height))) +struct CRGB& cLEDMatrixBase::operator()(int16_t i) +{ + if ((i >=0) && (i < (m_Width * m_Height))) return(m_LED[i]); else return(m_OutOfBounds); } -uint16_t cLEDMatrixBase::mXY(uint16_t x, uint16_t y) { - if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0; - - int16_t t; - switch(rotation) { - case 1: - t = x; - x = WIDTH - 1 - y; - y = t; - break; - case 2: - x = WIDTH - 1 - x; - y = HEIGHT - 1 - y; - break; - case 3: - t = x; - x = y; - y = HEIGHT - 1 - t; - break; - } - - int tileOffset = 0, pixelOffset; - - if(remapFn) { // Custom X/Y remapping function - pixelOffset = (*remapFn)(x, y); - } else { // Standard single matrix or tiled matrices - uint8_t corner = type & MTX_MATRIX_CORNER; - uint16_t minor, major, majorScale; - - if(tilesX) { // Tiled display, multiple matrices - uint16_t tile; - - minor = x / matrixWidth; // Tile # X/Y; presume row major to - major = y / matrixHeight, // start (will swap later if needed) - x = x - (minor * matrixWidth); // Pixel X/Y within tile - y = y - (major * matrixHeight); // (-* is less math than modulo) - - // Determine corner of entry, flip axes if needed - if(type & MTX_TILE_RIGHT) minor = tilesX - 1 - minor; - if(type & MTX_TILE_BOTTOM) major = tilesY - 1 - major; - - // Determine actual major axis of tiling - if((type & MTX_TILE_AXIS) == MTX_TILE_ROWS) { - majorScale = tilesX; - } else { - _swap_uint16_t(major, minor); - majorScale = tilesY; - } - - // Determine tile number - if((type & MTX_TILE_SEQUENCE) == MTX_TILE_PROGRESSIVE) { - // All tiles in same order - tile = major * majorScale + minor; - } else { - // Zigzag; alternate rows change direction. On these rows, - // this also flips the starting corner of the matrix for the - // pixel math later. - if(major & 1) { - corner ^= MTX_MATRIX_CORNER; - tile = (major + 1) * majorScale - 1 - minor; - } else { - tile = major * majorScale + minor; - } - } - // Index of first pixel in tile - tileOffset = tile * matrixWidth * matrixHeight; - } // else no tiling (handle as single tile) - - // Find pixel number within tile - minor = x; // Presume row major to start (will swap later if needed) - major = y; - - // Determine corner of entry, flip axes if needed - if(corner & MTX_MATRIX_RIGHT) minor = matrixWidth - 1 - minor; - if(corner & MTX_MATRIX_BOTTOM) major = matrixHeight - 1 - major; - - // Determine actual major axis of matrix - if((type & MTX_MATRIX_AXIS) == MTX_MATRIX_ROWS) { - majorScale = matrixWidth; - } else { - _swap_uint16_t(major, minor); - majorScale = matrixHeight; - } - - // Determine pixel number within tile/matrix - if((type & MTX_MATRIX_SEQUENCE) == MTX_MATRIX_PROGRESSIVE) { - // All lines in same order - pixelOffset = major * majorScale + minor; - } else { - // Zigzag; alternate rows change direction. - if(major & 1) pixelOffset = (major + 1) * majorScale - 1 - minor; - else pixelOffset = major * majorScale + minor; - } - } - return (tileOffset + pixelOffset); -} - -void cLEDMatrixBase::HorizontalMirror(bool FullHeight) { +void cLEDMatrixBase::HorizontalMirror(bool FullHeight) +{ int ty, y, x, xx; + if (FullHeight) - ty = _height - 1; + ty = m_Height - 1; else - ty = (_height / 2); - for (y=ty; y>=0; --y) { - for (x=(_width/2)-1,xx=((_width+1)/2); x>=0; --x,++xx) + ty = (m_Height / 2); + for (y=ty; y>=0; --y) + { + for (x=(m_Width/2)-1,xx=((m_Width+1)/2); x>=0; --x,++xx) m_LED[mXY(xx, y)] = m_LED[mXY(x, y)]; } } -void cLEDMatrixBase::VerticalMirror() { + +void cLEDMatrixBase::VerticalMirror() +{ int y, yy, x; - for (y=(_height/2)-1,yy=((_height+1)/2); y>=0; --y,++yy) { - for (x=_width-1; x>=0; --x) + + for (y=(m_Height/2)-1,yy=((m_Height+1)/2); y>=0; --y,++yy) + { + for (x=m_Width-1; x>=0; --x) m_LED[mXY(x, yy)] = m_LED[mXY(x, y)]; } } -void cLEDMatrixBase::QuadrantMirror() { + +void cLEDMatrixBase::QuadrantMirror() +{ HorizontalMirror(false); VerticalMirror(); } -void cLEDMatrixBase::QuadrantRotateMirror() { + +void cLEDMatrixBase::QuadrantRotateMirror() +{ int MaxXY, MidXY, x, y, src; - if (_width > _height) - MaxXY = _height; + + if (m_Width > m_Height) + MaxXY = m_Height; else - MaxXY = _width; + MaxXY = m_Width; MidXY = (MaxXY / 2); MaxXY--; - for (x=MidXY-(MaxXY%2); x>=0; --x) { - for (y=MidXY-(MaxXY%2); y>=0; --y) { + for (x=MidXY-(MaxXY%2); x>=0; --x) + { + for (y=MidXY-(MaxXY%2); y>=0; --y) + { src = mXY(x, y); m_LED[mXY(MidXY + y, MidXY - (MaxXY % 2) - x)] = m_LED[src]; m_LED[mXY(MaxXY - x, MaxXY - y)] = m_LED[src]; @@ -207,88 +95,150 @@ void cLEDMatrixBase::QuadrantRotateMirror() { } } -void cLEDMatrixBase::TriangleTopMirror(bool FullHeight) { + +void cLEDMatrixBase::TriangleTopMirror(bool FullHeight) +{ int MaxXY, x, y; - if (_width > _height) - MaxXY = _height - 1; + + if (m_Width > m_Height) + MaxXY = m_Height - 1; else - MaxXY = _width - 1; + MaxXY = m_Width - 1; if (! FullHeight) MaxXY /= 2; - for (y=1; y<=MaxXY; ++y) { + for (y=1; y<=MaxXY; ++y) + { for (x=0; x _height) - MaxXY = _height - 1; + + if (m_Width > m_Height) + MaxXY = m_Height - 1; else - MaxXY = _width - 1; + MaxXY = m_Width - 1; if (! FullHeight) MaxXY /= 2; - for (y=0,xx=MaxXY; y=0; --x,++yy) m_LED[mXY(xx, yy)] = m_LED[mXY(x, y)]; } } -void cLEDMatrixBase::QuadrantTopTriangleMirror() { + +void cLEDMatrixBase::QuadrantTopTriangleMirror() +{ TriangleTopMirror(false); QuadrantMirror(); } -void cLEDMatrixBase::QuadrantBottomTriangleMirror() { + +void cLEDMatrixBase::QuadrantBottomTriangleMirror() +{ TriangleBottomMirror(false); QuadrantMirror(); } -void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) { - drawLine(x0, y0, x1, y1, color); -} -void cLEDMatrixBase::DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) { - drawRect(x0, y0, (x1-x0), (y1-y0), color); -} - -void cLEDMatrixBase::DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color) { - drawCircle(xc, yc, r, color); -} - -void cLEDMatrixBase::DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB color) { - fillRect(x0, y0, (x1-x0), (y1-y0), color); -} - -void cLEDMatrixBase::DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color) { - fillCircle(xc, yc, r, color); -} - -void cLEDMatrixBase::drawPixel(int n, CRGB color) { - (*this)(n) = color; -} - -void cLEDMatrixBase::drawPixel(int16_t x, int16_t y, CRGB color) { - (*this)(x,y) = color; -} - -struct CRGB& cLEDMatrixBase::pixel(int n) { - return (*this)(n); -} - -struct CRGB& cLEDMatrixBase::pixel(int16_t x, int16_t y) { - return (*this)(x, y); +void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) +{ + int16_t dx = x1 - x0; + int16_t dy = y1 - y0; + if (abs(dx) >= abs(dy)) + { + int32_t f = ((int32_t)dy << 16) / (int32_t)abs(dx); + int32_t y = ((int32_t)y0 << 16) + 32768; + if (dx >= 0) + { + for (; x0<=x1; ++x0,y+=f) + (*this)(x0, (y >> 16)) = Col; + } + else + { + for (; x0>=x1; --x0,y+=f) + (*this)(x0, (y >> 16)) = Col; + } + } + else + { + int32_t f = ((int32_t)dx << 16) / (int32_t)abs(dy); + int32_t x = ((int32_t)x0 << 16) + 32768; + if (dy >= 0) + { + for (; y0<=y1; ++y0,x+=f) + (*this)((x >> 16), y0) = Col; + } + else + { + for (; y0>=y1; --y0,x+=f) + (*this)((x >> 16), y0) = Col; + } + } } -void cLEDMatrixBase::fillScreen(CRGB color) { - uint16_t i, n; - uint32_t c; - - n = Size(); - for(i=0; i x) || (e > y)) + e += (++x * 2) + 1; + } + while (x < 0); +} + + +void cLEDMatrixBase::DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) +{ + int16_t y = min(y0, y1); + for (int16_t c=abs(y1-y0); c>=0; --c,++y) + DrawLine(x0, y, x1, y, Col); +} + + +void cLEDMatrixBase::DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col) +{ + int16_t x = r; + int16_t y = 0; + int16_t e = 1 - x; + while (x >= y) + { + DrawLine(xc + x, yc + y, xc - x, yc + y, Col); + DrawLine(xc + y, yc + x, xc - y, yc + x, Col); + DrawLine(xc - x, yc - y, xc + x, yc - y, Col); + DrawLine(xc - y, yc - x, xc + y, yc - x, Col); + ++y; + if (e >= 0) + { + --x; + e += 2 * ((y - x) + 1); + } + else + e += (2 * y) + 1; + } } diff --git a/LEDMatrix.h b/LEDMatrix.h index 52494fd..1c3fc2d 100644 --- a/LEDMatrix.h +++ b/LEDMatrix.h @@ -1,476 +1,595 @@ -/*-------------------------------------------------------------------- - Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix - and on https://github.com/AaronLiddiment/LEDMatrix - replace internal use of NeoPixel library with CRGB array to use with FastLED - +/* + LEDMatrix V5 class by Aaron Liddiment (c) 2016 modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) date: 2016/04/27 - -------------------------------------------------------------------- - Original copyright & description below - -------------------------------------------------------------------- - This file is part of the Adafruit NeoMatrix library. - - NeoMatrix is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - NeoMatrix is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with NeoMatrix. If not, see - . - -------------------------------------------------------------------- - LEDMatrix V4 class by Aaron Liddiment (c) 2015 - Inspiration for some of the Matrix functions from Stefan Petrick - FastLED v3.1 library by Daniel Garcia and Mark Kriegsmann. - Written & tested on a Teensy 3.1 using Arduino V1.6.3 & teensyduino V1.22 - --------------------------------------------------------------------*/ - -#ifndef _LEDMATRIX_H_ -#define _LEDMATRIX_H_ - -#if ARDUINO >= 100 - #include -#else - #include - #include -#endif -#include - -// Matrix layout information is passed in the 'matrixType' parameter for -// each constructor. - -// These define the layout for a single 'unified' matrix (e.g. one made -// from NeoPixel strips, or a single NeoPixel shield), or for the pixels -// within each matrix of a tiled display (e.g. multiple NeoPixel shields). -#define MTX_MATRIX_TOP 0x00 // Pixel 0 is at top of matrix -#define MTX_MATRIX_BOTTOM 0x01 // Pixel 0 is at bottom of matrix -#define MTX_MATRIX_LEFT 0x00 // Pixel 0 is at left of matrix -#define MTX_MATRIX_RIGHT 0x02 // Pixel 0 is at right of matrix -#define MTX_MATRIX_CORNER 0x03 // Bitmask for pixel 0 matrix corner -#define MTX_MATRIX_ROWS 0x00 // Matrix is row major (horizontal) -#define MTX_MATRIX_COLUMNS 0x04 // Matrix is column major (vertical) -#define MTX_MATRIX_AXIS 0x04 // Bitmask for row/column layout -#define MTX_MATRIX_PROGRESSIVE 0x00 // Same pixel order across each line -#define MTX_MATRIX_ZIGZAG 0x08 // Pixel order reverses between lines -#define MTX_MATRIX_SEQUENCE 0x08 // Bitmask for pixel line order +*/ -// These apply only to tiled displays (multiple matrices): -#define MTX_TILE_TOP 0x00 // First tile is at top of matrix -#define MTX_TILE_BOTTOM 0x10 // First tile is at bottom of matrix -#define MTX_TILE_LEFT 0x00 // First tile is at left of matrix -#define MTX_TILE_RIGHT 0x20 // First tile is at right of matrix -#define MTX_TILE_CORNER 0x30 // Bitmask for first tile corner -#define MTX_TILE_ROWS 0x00 // Tiles ordered in rows -#define MTX_TILE_COLUMNS 0x40 // Tiles ordered in columns -#define MTX_TILE_AXIS 0x40 // Bitmask for tile H/V orientation -#define MTX_TILE_PROGRESSIVE 0x00 // Same tile order across each line -#define MTX_TILE_ZIGZAG 0x80 // Tile order reverses between lines -#define MTX_TILE_SEQUENCE 0x80 // Bitmask for tile line order +#ifndef LEDMatrix_h +#define LEDMatrix_h -class cLEDMatrixBase: public FastLED_GFX { -friend class cSprite; +enum MatrixType_t { HORIZONTAL_MATRIX, + VERTICAL_MATRIX, + HORIZONTAL_ZIGZAG_MATRIX, + VERTICAL_ZIGZAG_MATRIX }; -protected: - struct CRGB *m_LED; - struct CRGB m_OutOfBounds; - uint8_t type; - uint8_t matrixWidth; - uint8_t matrixHeight; - uint8_t tilesX; - uint8_t tilesY; - uint16_t (*remapFn)(uint16_t x, uint16_t y); +enum BlockType_t { HORIZONTAL_BLOCKS, + VERTICAL_BLOCKS, + HORIZONTAL_ZIGZAG_BLOCKS, + VERTICAL_ZIGZAG_BLOCKS }; -public: - cLEDMatrixBase(int w, int h); +class cLEDMatrixBase +{ + friend class cSprite; - virtual uint16_t mXY(uint16_t x, uint16_t y); - void SetLEDArray(struct CRGB *pLED); // Only used with externally defined LED arrays + protected: + int16_t m_Width, m_Height; + struct CRGB *m_LED; + struct CRGB m_OutOfBounds; - struct CRGB *operator[](int n); - struct CRGB &operator()(int16_t x, int16_t y); - struct CRGB &operator()(int16_t i); + public: + cLEDMatrixBase(); + virtual uint16_t mXY(uint16_t x, uint16_t y)=0; + void SetLEDArray(struct CRGB *pLED); // Only used with externally defined LED arrays - int Size() { return(_width * _height); } - int Width() { return(_width); } - int Height() { return(_height); } + struct CRGB *operator[](int n); + struct CRGB &operator()(int16_t x, int16_t y); + struct CRGB &operator()(int16_t i); - 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(); + int Size() { return(m_Width * m_Height); } + int Width() { return(m_Width); } + int Height() { return(m_Height); } - 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 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(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)); + void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); + void DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); + void DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col); + void DrawFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); + void DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col); }; -template class cLEDMatrix : public cLEDMatrixBase { -private: - static const int m_absWidth = (matrixW * (tX >0?tX:1)); - static const int m_absHeight = (matrixH * (tY >0?tY:1)); - struct CRGB p_LED[(m_absWidth * m_absHeight)]; -public: - cLEDMatrix() - : cLEDMatrixBase(m_absWidth, m_absHeight) { - type = matrixType; - matrixWidth = matrixW; - matrixHeight = matrixH; - tilesX = tX; - tilesY = tY; - remapFn = NULL; +template class cLEDMatrix : public cLEDMatrixBase +{ + private: + static const int16_t m_absMWidth = (tMWidth * ((tMWidth < 0) * -1 + (tMWidth > 0))); + static const int16_t m_absMHeight = (tMHeight * ((tMHeight < 0) * -1 + (tMHeight > 0))); + static const int16_t m_absBWidth = (tBWidth * ((tBWidth < 0) * -1 + (tBWidth > 0))); + static const int16_t m_absBHeight = (tBHeight * ((tBHeight < 0) * -1 + (tBHeight > 0))); + struct CRGB p_LED[m_absMWidth * m_absBWidth * m_absMHeight * m_absBHeight]; + + public: + cLEDMatrix() + { + m_Width = m_absMWidth * m_absBWidth; + m_Height = m_absMHeight * m_absBHeight; m_LED = p_LED; - } - void SetLEDArray(struct CRGB *pLED) { - m_LED = pLED; - } + } + void SetLEDArray(struct CRGB *pLED) + { + m_LED = pLED; + } + virtual uint16_t mXY(uint16_t x, uint16_t y) + { + if ((tBWidth == 1) && (tBHeight == 1)) + { + // No Blocks, just a Matrix + if (tMWidth < 0) + x = (m_absMWidth - 1) - x; + if (tMHeight < 0) + y = (m_absMHeight - 1) - y; + if (tMType == HORIZONTAL_MATRIX) + return((y * m_absMWidth) + x); + else if (tMType == VERTICAL_MATRIX) + return((x * m_absMHeight) + y); + else if (tMType == HORIZONTAL_ZIGZAG_MATRIX) + { + if (y % 2) + return((((y + 1) * m_absMWidth) - 1) - x); + else + return((y * m_absMWidth) + x); + } + else /* if (tMType == VERTICAL_ZIGZAG_MATRIX) */ + { + if (x % 2) + return((((x + 1) * m_absMHeight) - 1) - y); + else + return((x * m_absMHeight) + y); + } + } + else + { + // Reverse Block/Matrix X coordinate if needed + if ((tBWidth < 0) && (tMWidth < 0)) + x = (((m_absBWidth - 1) - (x / m_absMWidth)) * m_absMWidth) + ((m_absMWidth - 1) - (x % m_absMWidth)); + else if (tBWidth < 0) + x = (((m_absBWidth - 1) - (x / m_absMWidth)) * m_absMWidth) + (x % m_absMWidth); + else if (tMWidth < 0) + x = x - ((x % m_absMWidth) * 2) + (m_absMWidth - 1); + // Reverse Block/Matrix Y coordinate if needed + if ((tBHeight < 0) && (tMHeight < 0)) + y = (((m_absBHeight - 1) - (y / m_absMHeight)) * m_absMHeight) + ((m_absMHeight - 1) - (y % m_absMHeight)); + else if(tBHeight < 0) + y = (((m_absBHeight - 1) - (y / m_absMHeight)) * m_absMHeight) + (y % m_absMHeight); + else if (tMHeight < 0) + y = y - ((y % m_absMHeight) * 2) + (m_absMHeight - 1); + // Calculate Block base + uint16_t Base; + if (tBType == HORIZONTAL_BLOCKS) + Base = (((y / m_absMHeight) * m_absBWidth) + (x / m_absMWidth)) * (m_absMWidth * m_absMHeight); + else if (tBType == VERTICAL_BLOCKS) + Base = (((x / m_absMWidth) * m_absBHeight) + (y / m_absMHeight)) * (m_absMHeight * m_absMWidth); + else if (tBType == HORIZONTAL_ZIGZAG_BLOCKS) + { + if ((y / m_absMHeight) % 2) + Base = (((y / m_absMHeight) * m_absBWidth) + ((m_absBWidth - 1) - (x / m_absMWidth))) * (m_absMWidth * m_absMHeight); + else + Base = (((y / m_absMHeight) * m_absBWidth) + (x / m_absMWidth)) * (m_absMWidth * m_absMHeight); + } + else /* if (tBType == VERTICAL_ZIGZAG_BLOCKS) */ + { + if ((x / m_absMWidth) % 2) + Base = (((x / m_absMWidth) * m_absBHeight) + ((m_absBHeight - 1) - (y / m_absMHeight))) * (m_absMHeight * m_absMWidth); + else + Base = (((x / m_absMWidth) * m_absBHeight) + (y / m_absMHeight)) * (m_absMHeight * m_absMWidth); + } + // Calculate Matrix offset + if (tMType == HORIZONTAL_MATRIX) + return(Base + ((y % m_absMHeight) * m_absMWidth) + (x % m_absMWidth)); + else if (tMType == VERTICAL_MATRIX) + return(Base + ((x % m_absMWidth) * m_absMHeight) + (y % m_absMHeight)); + else if (tMType == HORIZONTAL_ZIGZAG_MATRIX) + { + if ((y % m_absMHeight) % 2) + return(Base + ((((y % m_absMHeight) + 1) * m_absMWidth) - 1) - (x % m_absMWidth)); + else + return(Base + ((y % m_absMHeight) * m_absMWidth) + (x % m_absMWidth)); + } + else /* if (tMType == VERTICAL_ZIGZAG_MATRIX) */ + { + if ((x % m_absMWidth) % 2) + return(Base + ((((x % m_absMWidth) + 1) * m_absMHeight) - 1) - (y % m_absMHeight)); + else + return(Base + ((x % m_absMWidth) * m_absMHeight) + (y % m_absMHeight)); + } + } + } - void ShiftLeft(void) { - /* t.b.d. - switch (tMType) { - case HORIZONTAL_MATRIX: - if (tWidth > 0) - HPWSL(); - else - HNWSL(); - break; - case VERTICAL_MATRIX: - if (tWidth > 0) - VPWSL(); - else - VNWSL(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tWidth > 0) - HZPWSL(); - else - HZNWSL(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tWidth > 0) - VZPWSL(); - else - VZNWSL(); - break; + void ShiftLeft(void) + { + if ((tBWidth != 1) || (tBHeight != 1)) + { + // Blocks, so no optimisation + for (int16_t x=1; x 0) + HPWSL(); + else + HNWSL(); + break; + case VERTICAL_MATRIX: + if (tMWidth > 0) + VPWSL(); + else + VNWSL(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tMWidth > 0) + HZPWSL(); + else + HZNWSL(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tMWidth > 0) + VZPWSL(); + else + VZNWSL(); + break; + } + } } - */ - } - void ShiftRight(void) { - /* - switch (tMType) { - case HORIZONTAL_MATRIX: - if (tWidth > 0) - HNWSL(); - else - HPWSL(); - break; - case VERTICAL_MATRIX: - if (tWidth > 0) - VNWSL(); - else - VPWSL(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tWidth > 0) - HZNWSL(); - else - HZPWSL(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tWidth > 0) - VZNWSL(); - else - VZPWSL(); - break; + void ShiftRight(void) + { + if ((tBWidth != 1) || (tBHeight != 1)) + { + // Blocks, so no optimisation + for (int16_t x=m_Width-1; x>=1; --x) + { + for (int16_t y=0; y 0) + HNWSL(); + else + HPWSL(); + break; + case VERTICAL_MATRIX: + if (tMWidth > 0) + VNWSL(); + else + VPWSL(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tMWidth > 0) + HZNWSL(); + else + HZPWSL(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tMWidth > 0) + VZNWSL(); + else + VZPWSL(); + break; + } + } } - */ - } - void ShiftDown(void) { - /* - switch (tMType) { - case HORIZONTAL_MATRIX: - if (tHeight > 0) - HPHSD(); - else - HNHSD(); - break; - case VERTICAL_MATRIX: - if (tHeight > 0) - VPHSD(); - else - VNHSD(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tHeight > 0) - HZPHSD(); - else - HZNHSD(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tHeight > 0) - VZPHSD(); - else - VZNHSD(); - break; + void ShiftDown(void) + { + if ((tBWidth != 1) || (tBHeight != 1)) + { + // Blocks, so no optimisation + for (int16_t y=1; y 0) + HPHSD(); + else + HNHSD(); + break; + case VERTICAL_MATRIX: + if (tMHeight > 0) + VPHSD(); + else + VNHSD(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tMHeight > 0) + HZPHSD(); + else + HZNHSD(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tMHeight > 0) + VZPHSD(); + else + VZNHSD(); + break; + } + } } - */ - } - void ShiftUp(void) { - /* - switch (tMType) + void ShiftUp(void) { - case HORIZONTAL_MATRIX: - if (tHeight > 0) - HNHSD(); - else - HPHSD(); - break; - case VERTICAL_MATRIX: - if (tHeight > 0) - VNHSD(); - else - VPHSD(); - break; - case HORIZONTAL_ZIGZAG_MATRIX: - if (tHeight > 0) - HZNHSD(); - else - HZPHSD(); - break; - case VERTICAL_ZIGZAG_MATRIX: - if (tHeight > 0) - VZNHSD(); - else - VZPHSD(); - break; + if ((tBWidth != 1) || (tBHeight != 1)) + { + // Blocks, so no optimisation + for (int16_t y=m_Height-1; y>=1; --y) + { + for (int16_t x=0; x 0) + HNHSD(); + else + HPHSD(); + break; + case VERTICAL_MATRIX: + if (tMHeight > 0) + VNHSD(); + else + VPHSD(); + break; + case HORIZONTAL_ZIGZAG_MATRIX: + if (tMHeight > 0) + HZNHSD(); + else + HZPHSD(); + break; + case VERTICAL_ZIGZAG_MATRIX: + if (tMHeight > 0) + VZNHSD(); + else + VZPHSD(); + break; + } + } } - */ - } -private: - // Functions used by ShiftLeft & ShiftRight - void HPWSL(void) { - int16_t i = 0; - for (int16_t y=m_absHeight; y>0; --y,++i) { - for (int16_t x=m_absWidth-1; x>0; --x,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); + private: + // Optimised functions used by ShiftLeft & ShiftRight in non block mode + void HPWSL(void) + { + int16_t i = 0; + for (int16_t y=m_absMHeight; y>0; --y,++i) + { + for (int16_t x=m_absMWidth-1; x>0; --x,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); + } } - } - void HNWSL(void) { - int16_t i = m_absWidth - 1; - for (int16_t y=m_absHeight; y>0; --y) { - for (int16_t x=m_absWidth-1; x>0; --x,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - i += ((m_absWidth * 2) - 1); + void HNWSL(void) + { + int16_t i = m_absMWidth - 1; + for (int16_t y=m_absMHeight; y>0; --y) + { + for (int16_t x=m_absMWidth-1; x>0; --x,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += ((m_absMWidth * 2) - 1); + } } - } - void VPWSL(void) { - int16_t i = 0; - int16_t j = m_absHeight; - for (int16_t x=m_absWidth-1; x>0; --x) { - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i++] = p_LED[j++]; + void VPWSL(void) + { + int16_t i = 0; + int16_t j = m_absMHeight; + for (int16_t x=m_absMWidth-1; x>0; --x) + { + for (int16_t y=m_absMHeight; y>0; --y) + p_LED[i++] = p_LED[j++]; + } + for (int16_t y=m_absMHeight; y>0; --y) + p_LED[i++] = CRGB(0, 0, 0); } - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i++] = CRGB(0, 0, 0); - } - void VNWSL(void) { - int16_t i = (m_absHeight * m_absWidth) - 1; - int16_t j = i - m_absHeight; - for (int16_t x=m_absWidth-1; x>0; --x) { - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i--] = p_LED[j--]; + void VNWSL(void) + { + int16_t i = (m_absMHeight * m_absMWidth) - 1; + int16_t j = i - m_absMHeight; + for (int16_t x=m_absMWidth-1; x>0; --x) + { + for (int16_t y=m_absMHeight; y>0; --y) + p_LED[i--] = p_LED[j--]; + } + for (int16_t y=m_absMHeight; y>0; --y) + p_LED[i--] = CRGB(0, 0, 0); } - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i--] = CRGB(0, 0, 0); - } - void HZPWSL(void) { - int16_t i = 0; - for (int16_t y=m_absHeight; y>0; y-=2) { - for (int16_t x=m_absWidth-1; x>0; --x,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); - i++; - if (y > 1) { - i += (m_absWidth - 1); - for (int16_t x=m_absWidth-1; x>0; --x,--i) - p_LED[i] = p_LED[i - 1]; + void HZPWSL(void) + { + int16_t i = 0; + for (int16_t y=m_absMHeight; y>0; y-=2) + { + for (int16_t x=m_absMWidth-1; x>0; --x,++i) + p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); - i += m_absWidth; + i++; + if (y > 1) + { + i += (m_absMWidth - 1); + for (int16_t x=m_absMWidth-1; x>0; --x,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += m_absMWidth; + } } } - } - void HZNWSL(void) { - int16_t i = m_absWidth - 1; - for (int16_t y=m_absHeight; y>0; y-=2) { - for (int16_t x=m_absWidth-1; x>0; --x,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - if (y > 1) { - i += m_absWidth; - for (int16_t x=m_absWidth-1; x>0; --x,++i) - p_LED[i] = p_LED[i + 1]; + void HZNWSL(void) + { + int16_t i = m_absMWidth - 1; + for (int16_t y=m_absMHeight; y>0; y-=2) + { + for (int16_t x=m_absMWidth-1; x>0; --x,--i) + p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); - i += m_absWidth; + if (y > 1) + { + i += m_absMWidth; + for (int16_t x=m_absMWidth-1; x>0; --x,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); + i += m_absMWidth; + } } } - } - void VZPWSL(void) { - int16_t i = 0; - int16_t j = (m_absHeight * 2) - 1; - for (int16_t x=m_absWidth-1; x>0; x-=2) { - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i++] = p_LED[j--]; - if (x > 1) { - j += (m_absHeight * 2); - for (int16_t y=m_absHeight; y>0; --y) + void VZPWSL(void) + { + int16_t i = 0; + int16_t j = (m_absMHeight * 2) - 1; + for (int16_t x=m_absMWidth-1; x>0; x-=2) + { + for (int16_t y=m_absMHeight; y>0; --y) p_LED[i++] = p_LED[j--]; - j += (m_absHeight * 2); + if (x > 1) + { + j += (m_absMHeight * 2); + for (int16_t y=m_absMHeight; y>0; --y) + p_LED[i++] = p_LED[j--]; + j += (m_absMHeight * 2); + } } + for (int16_t y=m_absMHeight; y>0; y--) + p_LED[i++] = CRGB(0, 0, 0); } - for (int16_t y=m_absHeight; y>0; y--) - p_LED[i++] = CRGB(0, 0, 0); - } - void VZNWSL(void) { - int16_t i = (m_absHeight * m_absWidth) - 1; - int16_t j = m_absHeight * (m_absWidth - 2); - for (int16_t x=m_absWidth-1; x>0; x-=2) { - for (int16_t y=m_absHeight; y>0; --y) - p_LED[i--] = p_LED[j++]; - if (x > 1) { - j -= (m_absHeight * 2); - for (int16_t y=m_absHeight; y>0; --y) + void VZNWSL(void) + { + int16_t i = (m_absMHeight * m_absMWidth) - 1; + int16_t j = m_absMHeight * (m_absMWidth - 2); + for (int16_t x=m_absMWidth-1; x>0; x-=2) + { + for (int16_t y=m_absMHeight; y>0; --y) p_LED[i--] = p_LED[j++]; - j -= (m_absHeight * 2); + if (x > 1) + { + j -= (m_absMHeight * 2); + for (int16_t y=m_absMHeight; y>0; --y) + p_LED[i--] = p_LED[j++]; + j -= (m_absMHeight * 2); + } } + for (int16_t y=m_absMHeight; y>0; y--) + p_LED[i--] = CRGB(0, 0, 0); } - for (int16_t y=m_absHeight; y>0; y--) - p_LED[i--] = CRGB(0, 0, 0); - } - // Functions used by ShiftDown & ShiftUp - void HPHSD(void) { - int16_t i = 0; - int16_t j = m_absWidth; - for (int16_t y=m_absHeight-1; y>0; --y) { - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i++] = p_LED[j++]; + // Optimised functions used by ShiftDown & ShiftUp in non block mode + void HPHSD(void) + { + int16_t i = 0; + int16_t j = m_absMWidth; + for (int16_t y=m_absMHeight-1; y>0; --y) + { + for (int16_t x=m_absMWidth; x>0; --x) + p_LED[i++] = p_LED[j++]; + } + for (int16_t x=m_absMWidth; x>0; --x) + p_LED[i++] = CRGB(0, 0, 0); } - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i++] = CRGB(0, 0, 0); - } - void HNHSD(void) { - int16_t i = (m_absWidth * m_absHeight) - 1; - int16_t j = i - m_absWidth; - for (int16_t y=m_absHeight-1; y>0; --y) { - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i--] = p_LED[j--]; + void HNHSD(void) + { + int16_t i = (m_absMWidth * m_absMHeight) - 1; + int16_t j = i - m_absMWidth; + for (int16_t y=m_absMHeight-1; y>0; --y) + { + for (int16_t x=m_absMWidth; x>0; --x) + p_LED[i--] = p_LED[j--]; + } + for (int16_t x=m_absMWidth; x>0; --x) + p_LED[i--] = CRGB(0, 0, 0); } - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i--] = CRGB(0, 0, 0); - } - void VPHSD(void) { - int16_t i = 0; - for (int16_t x=m_absWidth; x>0; --x,++i) { - for (int16_t y=m_absHeight-1; y>0; --y,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); + void VPHSD(void) + { + int16_t i = 0; + for (int16_t x=m_absMWidth; x>0; --x,++i) + { + for (int16_t y=m_absMHeight-1; y>0; --y,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); + } } - } - void VNHSD(void) { - int16_t i = m_absHeight - 1; - for (int16_t x=m_absWidth; x>0; --x) { - for (int16_t y=m_absHeight-1; y>0; --y,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - i += ((m_absHeight * 2) - 1); + void VNHSD(void) + { + int16_t i = m_absMHeight - 1; + for (int16_t x=m_absMWidth; x>0; --x) + { + for (int16_t y=m_absMHeight-1; y>0; --y,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += ((m_absMHeight * 2) - 1); + } } - } - void HZPHSD(void) { - int16_t i = 0; - int16_t j = (m_absWidth * 2) - 1; - for (int16_t y=m_absHeight-1; y>0; y-=2) { - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i++] = p_LED[j--]; - if (y > 1) { - j += (m_absWidth * 2); - for (int16_t x=m_absWidth; x>0; --x) + void HZPHSD(void) + { + int16_t i = 0; + int16_t j = (m_absMWidth * 2) - 1; + for (int16_t y=m_absMHeight-1; y>0; y-=2) + { + for (int16_t x=m_absMWidth; x>0; --x) p_LED[i++] = p_LED[j--]; - j += (m_absWidth * 2); + if (y > 1) + { + j += (m_absMWidth * 2); + for (int16_t x=m_absMWidth; x>0; --x) + p_LED[i++] = p_LED[j--]; + j += (m_absMWidth * 2); + } } + for (int16_t x=m_absMWidth; x>0; x--) + p_LED[i++] = CRGB(0, 0, 0); } - for (int16_t x=m_absWidth; x>0; x--) - p_LED[i++] = CRGB(0, 0, 0); - } - void HZNHSD(void) { - int16_t i = (m_absWidth * m_absHeight) - 1; - int16_t j = m_absWidth * (m_absHeight - 2); - for (int16_t y=m_absHeight-1; y>0; y-=2) { - for (int16_t x=m_absWidth; x>0; --x) - p_LED[i--] = p_LED[j++]; - if (y > 1) { - j -= (m_absWidth * 2); - for (int16_t x=m_absWidth; x>0; --x) + void HZNHSD(void) + { + int16_t i = (m_absMWidth * m_absMHeight) - 1; + int16_t j = m_absMWidth * (m_absMHeight - 2); + for (int16_t y=m_absMHeight-1; y>0; y-=2) + { + for (int16_t x=m_absMWidth; x>0; --x) p_LED[i--] = p_LED[j++]; - j -= (m_absWidth * 2); + if (y > 1) + { + j -= (m_absMWidth * 2); + for (int16_t x=m_absMWidth; x>0; --x) + p_LED[i--] = p_LED[j++]; + j -= (m_absMWidth * 2); + } } + for (int16_t x=m_absMWidth; x>0; x--) + p_LED[i--] = CRGB(0, 0, 0); } - for (int16_t x=m_absWidth; x>0; x--) - p_LED[i--] = CRGB(0, 0, 0); - } - void VZPHSD(void) { - int16_t i = 0; - for (int16_t x=m_absWidth; x>0; x-=2) { - for (int16_t y=m_absHeight-1; y>0; --y,++i) - p_LED[i] = p_LED[i + 1]; - p_LED[i] = CRGB(0, 0, 0); - i++; - if (x > 1) { - i += (m_absHeight - 1); - for (int16_t y=m_absHeight-1; y>0; --y,--i) - p_LED[i] = p_LED[i - 1]; + void VZPHSD(void) + { + int16_t i = 0; + for (int16_t x=m_absMWidth; x>0; x-=2) + { + for (int16_t y=m_absMHeight-1; y>0; --y,++i) + p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); - i += m_absHeight; + i++; + if (x > 1) + { + i += (m_absMHeight - 1); + for (int16_t y=m_absMHeight-1; y>0; --y,--i) + p_LED[i] = p_LED[i - 1]; + p_LED[i] = CRGB(0, 0, 0); + i += m_absMHeight; + } } } - } - void VZNHSD(void) { - int16_t i = m_absHeight - 1; - for (int16_t x=m_absWidth; x>0; x-=2) { - for (int16_t y=m_absHeight-1; y>0; --y,--i) - p_LED[i] = p_LED[i - 1]; - p_LED[i] = CRGB(0, 0, 0); - if (x > 1) { - i += m_absHeight; - for (int16_t y=m_absHeight-1; y>0; --y,++i) - p_LED[i] = p_LED[i + 1]; + void VZNHSD(void) + { + int16_t i = m_absMHeight - 1; + for (int16_t x=m_absMWidth; x>0; x-=2) + { + for (int16_t y=m_absMHeight-1; y>0; --y,--i) + p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); - i += m_absHeight; + if (x > 1) + { + i += m_absMHeight; + for (int16_t y=m_absMHeight-1; y>0; --y,++i) + p_LED[i] = p_LED[i + 1]; + p_LED[i] = CRGB(0, 0, 0); + i += m_absMHeight; + } } } - } + }; -#endif // _LEDMATRIX_H_ +#endif diff --git a/examples/MatrixExample1/MatrixExample1.ino b/examples/MatrixExample1/MatrixExample1.ino index f486134..48fbe94 100644 --- a/examples/MatrixExample1/MatrixExample1.ino +++ b/examples/MatrixExample1/MatrixExample1.ino @@ -1,25 +1,31 @@ #include -#include // https://github.com/Jorgen-VikingGod/FastLED-GFX #include -// Change the next 6 defines to match your matrix type and size +// Change the next defines to match your matrix type and size +#define DATA_PIN D5 -#define LED_PIN 2 -#define COLOR_ORDER GRB -#define CHIPSET WS2812B +#define COLOR_ORDER GRB +#define CHIPSET WS2812B -#define MATRIX_WIDTH 80 // Set this negative if physical led 0 is opposite to where you want logical 0 -#define MATRIX_HEIGHT 10 // Set this negative if physical led 0 is opposite to where you want logical 0 -#define MATRIX_TYPE (MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG) // See top of LEDMatrix.h for matrix wiring types +// 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 leds; + uint8_t hue; int16_t counter; void setup() { - FastLED.addLeds(leds[0], leds.Size()); + // initial LEDs + FastLED.addLeds(leds[0], leds.Size()).setCorrection(TypicalSMD5050); + FastLED.setCorrection(TypicalLEDStrip); FastLED.setBrightness(127); FastLED.clear(true); delay(500); diff --git a/examples/MatrixExample2/MatrixExample2.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino similarity index 71% rename from examples/MatrixExample2/MatrixExample2.ino rename to examples/MatrixTilesExample/MatrixTilesExample.ino index 674e92a..f546c75 100644 --- a/examples/MatrixExample2/MatrixExample2.ino +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -1,18 +1,30 @@ #include -#include // https://github.com/Jorgen-VikingGod/FastLED-GFX #include -// Change the next 6 defines to match your matrix type and size +// 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 LED_PIN 2 -#define COLOR_ORDER GRB -#define CHIPSET WS2812B +#define COLOR_ORDER BGR +#define CHIPSET APA102 -#define MATRIX_WIDTH 80 // Set this negative if physical led 0 is opposite to where you want logical 0 -#define MATRIX_HEIGHT 10 // Set this negative if physical led 0 is opposite to where you want logical 0 -#define MATRIX_TYPE (MTX_MATRIX_TOP + MTX_MATRIX_LEFT + MTX_MATRIX_ROWS + MTX_MATRIX_ZIGZAG) // See top of LEDMatrix.h for matrix wiring types +#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 +#define MATRIX_TILE_V 8 // number of matrices arranged vertically +#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 leds; -cLEDMatrix leds; uint8_t angle = 0; diff --git a/examples/matrixtest/matrixtest.ino b/examples/matrixtest/matrixtest.ino deleted file mode 100644 index bb182af..0000000 --- a/examples/matrixtest/matrixtest.ino +++ /dev/null @@ -1,75 +0,0 @@ -// Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix -// replace internal use of NeoPixel library with CRGB array to use with FastLED -// -// modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) -// date: 2016/04/27 -// -------------------------------------------------------------------- -// Original copyright & description below -// -------------------------------------------------------------------- -// Adafruit_NeoMatrix example for single NeoPixel Shield. -// Scrolls 'Howdy' across the matrix in a portrait (vertical) orientation. - -#include -#include -#include - -#define LED_PIN 2 -#define COLOR_ORDER GRB -#define CHIPSET WS2812B - -#define MATRIX_WIDTH 5 // width of FastLED 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 - -// MATRIX DECLARATION: -// Parameter 1 = width of FastLED matrix -// Parameter 2 = height of matrix -// Parameter 3 = matrix layout flags, add together as needed: -// MTX_MATRIX_TOP, MTX_MATRIX_BOTTOM, MTX_MATRIX_LEFT, MTX_MATRIX_RIGHT: -// Position of the FIRST LED in the matrix; pick two, e.g. -// MTX_MATRIX_TOP + MTX_MATRIX_LEFT for the top-left corner. -// MTX_MATRIX_ROWS, MTX_MATRIX_COLUMNS: LEDs are arranged in horizontal -// rows or in vertical columns, respectively; pick one or the other. -// MTX_MATRIX_PROGRESSIVE, MTX_MATRIX_ZIGZAG: all rows/columns proceed -// in the same order, or alternate lines reverse direction; pick one. -// See example below for these values in action. - - -// Example for NeoPixel Shield. In this application we'd like to use it -// as a 5x8 tall matrix, with the USB port positioned at the top of the -// Arduino. When held that way, the first pixel is at the top right, and -// lines are arranged in columns, progressive order. - -cLEDMatrix matrix; - -const CRGB colors[] = { - CRGB(255, 0, 0), - CRGB(0, 255, 0), - CRGB(0, 0, 255) -}; - -void setup() { - // initial FastLED - FastLED.addLeds(matrix[0], matrix.Size()); - FastLED.setBrightness(127); - FastLED.clear(true); - - matrix.setTextWrap(false); - matrix.setTextColor(colors[0]); -} - -int x = matrix.width(); -int pass = 0; - -void loop() { - matrix.fillScreen(0); - matrix.setCursor(x, 0); - matrix.print(F("Howdy")); - if(--x < -36) { - x = matrix.width(); - if(++pass >= 3) pass = 0; - matrix.setTextColor(colors[pass]); - } - FastLED.show(); - delay(100); -} diff --git a/examples/tiletest/tiletest.ino b/examples/tiletest/tiletest.ino deleted file mode 100644 index c964c56..0000000 --- a/examples/tiletest/tiletest.ino +++ /dev/null @@ -1,111 +0,0 @@ -// Source code is based on https://github.com/adafruit/Adafruit_NeoMatrix -// replace internal use of NeoPixel library with CRGB array to use with FastLED -// -// modified: Juergen Skrotzky (JorgenVikingGod@gmail.com) -// date: 2016/04/27 -// -------------------------------------------------------------------- -// Original copyright & description below -// -------------------------------------------------------------------- -// Adafruit_NeoMatrix example for tiled NeoPixel matrices. Scrolls -// 'Howdy' across three 10x8 NeoPixel grids that were created using -// NeoPixel 60 LEDs per meter flex strip. - -#include -#include -#include - -#define LED_PIN 2 -#define COLOR_ORDER GRB -#define CHIPSET WS2812B - -#define TARGET_FRAME_TIME 25 // Desired update rate, though if too many leds it will just run as fast as it can! -#define PLASMA_X_FACTOR 24 -#define PLASMA_Y_FACTOR 24 - -// MATRIX DECLARATION: -// 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: -// MTX_MATRIX_TOP, MTX_MATRIX_BOTTOM, MTX_MATRIX_LEFT, MTX_MATRIX_RIGHT: -// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g. -// MTX_MATRIX_TOP + MTX_MATRIX_LEFT for the top-left corner. -// MTX_MATRIX_ROWS, MTX_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are -// arranged in horizontal rows or in vertical columns, respectively; -// pick one or the other. -// MTX_MATRIX_PROGRESSIVE, MTX_MATRIX_ZIGZAG: all rows/columns WITHIN -// EACH MATRIX proceed in the same order, or alternate lines reverse -// direction; pick one. -// MTX_TILE_TOP, MTX_TILE_BOTTOM, MTX_TILE_LEFT, MTX_TILE_RIGHT: -// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick -// two, e.g. MTX_TILE_TOP + MTX_TILE_LEFT for the top-left corner. -// MTX_TILE_ROWS, MTX_TILE_COLUMNS: the matrices in the OVERALL DISPLAY -// are arranged in horizontal rows or in vertical columns, respectively; -// pick one or the other. -// MTX_TILE_PROGRESSIVE, MTX_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES -// (tiles) in the OVERALL DISPLAY proceed in the same order for every -// line, or alternate lines reverse direction; pick one. When using -// zig-zag order, the orientation of the matrices in alternate rows -// will be rotated 180 degrees (this is normal -- simplifies wiring). -// Parameter 4 = number of matrices arranged horizontally -// Parameter 5 = number of matrices arranged vertically -// See example below for these values in action. - -// Example with three 10x8 matrices (created using NeoPixel flex strip -- -// these grids are not a ready-made product). In this application we'd -// like to arrange the three matrices side-by-side in a wide display. -// The first matrix (tile) will be at the left, and the first pixel within -// that matrix is at the top left. The matrices use zig-zag line ordering. -// There's only one row here, so it doesn't matter if we declare it in row -// or column order. The matrices use 800 KHz (v2) pixels that expect GRB -// color data. - -#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) - -cLEDMatrix matrix; - -uint16_t PlasmaTime, PlasmaShift; -uint32_t LoopDelayMS, LastLoop; - -void ESP8266_yield() { -#ifdef ESP8266 - yield(); // secure time for the WiFi stack of ESP8266 -#endif -} - -void setup() { - // initial FastLED - FastLED.addLeds(matrix[0], matrix.Size()); - FastLED.setBrightness(128); - FastLED.clear(true); - // initial helpers for plasma animation - LoopDelayMS = TARGET_FRAME_TIME; - LastLoop = millis() - LoopDelayMS; - PlasmaShift = (random8(0, 5) * 32) + 64; - PlasmaTime = 0; -} - -void loop() { - if (abs(millis() - LastLoop) >= LoopDelayMS) { - LastLoop = millis(); - FastLED.clear(); - // Fill background with dim plasma - for (int16_t x=0; x PlasmaTime) - PlasmaShift = (random8(0, 5) * 32) + 64; - FastLED.show(); - } -} From a3ed16424457dbcc331c21151c5d0e1182bc378b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 15:54:59 +0100 Subject: [PATCH 18/35] update FastLED initial --- examples/MatrixTilesExample/MatrixTilesExample.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino index f546c75..5427606 100644 --- a/examples/MatrixTilesExample/MatrixTilesExample.ino +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -30,7 +30,8 @@ uint8_t angle = 0; void setup() { - FastLED.addLeds(leds[0], leds.Size()); + FastLED.addLeds(leds[0], 0, leds.Size()/2).setCorrection(TypicalSMD5050); + FastLED.addLeds(leds[0], leds.Size()/2, leds.Size()/2).setCorrection(TypicalSMD5050); FastLED.setBrightness(127); FastLED.clear(true); delay(500); From 044df7a88b8c7786dfe3e9baf7419b189bbf010a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:07:03 +0100 Subject: [PATCH 19/35] update defines, examples and methods --- README.md | 178 +++++++++++++++++++++++------------------------------- 1 file changed, 74 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index 941aa5d..da8711d 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,14 @@ [![FastLED dependencies](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) [![FastLED-GFX dependencies](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) -> A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and FastLED port of ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) by using the graphics library [FastLED-GFX](https://github.com/Jorgen-VikingGod/FastLED-GFX) (based on [Adafruit-GFX-Library](https://github.com/adafruit/Adafruit-GFX-Library)) +> A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and build in some features from ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) 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 Adafruit-NeoMatrix and cLEDMatrix 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. + 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.
@@ -39,11 +39,6 @@ Once you have downloaded the Zip file, it should be extracted into your Arduino
  • Available Methods
  • -
  • Graphic Library - -
  • - 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. + 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).
    @@ -52,92 +47,125 @@ Once you have downloaded the Zip file, it should be extracted into your Arduino
    -## Single Matrix ([Example](examples/matrixtest/matrixtest.ino)) +## Single Matrix ([Example](examples/MatrixExample1/MatrixExample1.ino)) ---------------------------------------------------------------- ### Parameters | Parameter | Description | | ------------ |---------------------------------------------| | Parameter 1 | width of matrix | | Parameter 2 | height of matrix | -| Parameter 3 | matrix layout flags, add together as needed | +| Parameter 3 | MatrixType_t = matrix layout type | + +```c +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 ```c #include -#include #include ``` ### Decleration ```c -// declare FastLED (matrix / LED strip) -#define LED_PIN 2 -#define COLOR_ORDER GRB -#define CHIPSET WS2812B +// Change the next defines to match your matrix type and size +#define DATA_PIN D5 + +#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 +// 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; +cLEDMatrix leds; ``` ### Initialize FastLED ```c void setup() { // initial FastLED by using CRGB led source from our matrix class - FastLED.addLeds(matrix[0], matrix.Size()); + FastLED.addLeds(leds[0], leds.Size()).setCorrection(TypicalSMD5050); FastLED.setBrightness(127); FastLED.clear(true); } ``` -## Tile Matrix ([Example](examples/tiletest/tiletest.ino)) +## Tile Matrix ([Example](examples/MatrixTilesExample/MatrixTilesExample.ino)) ---------------------------------------------------------------- ### 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 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 | +```c +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 ```c #include -#include #include ``` ### Decleration ```c -// 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) +// 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 +#define MATRIX_TILE_V 8 // number of matrices arranged vertically +#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; +cLEDMatrix leds; ``` ### Initialize FastLED ```c void setup() { // initial FastLED by using CRGB led source from our matrix class - FastLED.addLeds(matrix[0], matrix.Size()); + FastLED.addLeds(leds[0], leds.Size()); FastLED.setBrightness(127); FastLED.clear(true); } @@ -146,15 +174,9 @@ void setup() { ### Initialize FastLED (multiple controller) ```c void setup() { - // initial FastLED with multiple controller, by using CRGB led source from each matrix panal - // panel 1 (from 0 to 255) - FastLED.addLeds(matrix[0], 0, MATRIX_SIZE); - // panel 2 (from 255 to 511) - FastLED.addLeds(matrix[0], 1*MATRIX_SIZE, MATRIX_SIZE); - // panel 3 (from 512 to 767) - FastLED.addLeds(matrix[0], 2*MATRIX_SIZE, MATRIX_SIZE); - // panel 4 (from 768 to 1023) - FastLED.addLeds(matrix[0], 3*MATRIX_SIZE, MATRIX_SIZE); + // initial FastLED with multiple controller, by using CRGB led source from each matrix panal + FastLED.addLeds(leds[0], 0, leds.Size()/2).setCorrection(TypicalSMD5050); + FastLED.addLeds(leds[0], leds.Size()/2, leds.Size()/2).setCorrection(TypicalSMD5050); FastLED.setBrightness(127); FastLED.clear(true); } @@ -162,9 +184,14 @@ void setup() { ## Available Methods ```c -uint16_t mXY(uint16_t x, uint16_t y) +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) @@ -187,61 +214,4 @@ 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](https://github.com/Jorgen-VikingGod/FastLED-GFX)) ----------------------------------------------------------------- -Simple FastLED port of ([Adafruit-GFX-Library](https://github.com/adafruit/Adafruit-GFX-Library)) - -### Available Methods -```c -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 ``` From fbf99147bd5e3d17a05419637ef388d6cdd95b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:10:03 +0100 Subject: [PATCH 20/35] Update MatrixTilesExample.ino --- examples/MatrixTilesExample/MatrixTilesExample.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino index 5427606..274c004 100644 --- a/examples/MatrixTilesExample/MatrixTilesExample.ino +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -25,7 +25,6 @@ // create our matrix based on matrix definition cLEDMatrix leds; - uint8_t angle = 0; void setup() From 1b3fc129876ba28f44ca7da2bd5b78a47070635f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:15:42 +0100 Subject: [PATCH 21/35] Update .travis.yml --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a7dc8fd..036bdab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,6 @@ install: # install lib arduino json not working in 1.6.5 # - arduino --install-library "FastLED" - git clone https://github.com/FastLED/FastLED /usr/local/share/arduino/libraries/FastLED -# - arduino --install-library "FastLED-GFX" - - git clone https://github.com/Jorgen-VikingGod/FastLED-GFX /usr/local/share/arduino/libraries/FastLED-GFX - arduino --install-boards esp8266:esp8266 - arduino --board esp8266:esp8266:generic --save-prefs - arduino --pref "compiler.warning_level=all" --save-prefs @@ -26,9 +24,6 @@ script: - source $TRAVIS_BUILD_DIR/travis/common.sh - build_examples # - "cat $PWD/examples/MatrixExample1/MatrixExample1.ino" -# - arduino -v --verbose-build --verify $PWD/examples/MatrixExample1/MatrixExample1.ino -# - arduino --verify --board arduino:avr:uno $PWD/examples/IncomingCall/IncomingCall.ino -# - arduino --verify --board arduino:avr:uno $PWD/examples/AdafruitIO_GPS/AdafruitIO_GPS.ino notifications: email: on_success: change From a533c511aa855bdcc0039b256175fe05b1534014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:18:02 +0100 Subject: [PATCH 22/35] change pin to ESP8266 generic --- examples/MatrixExample1/MatrixExample1.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MatrixExample1/MatrixExample1.ino b/examples/MatrixExample1/MatrixExample1.ino index 48fbe94..5817517 100644 --- a/examples/MatrixExample1/MatrixExample1.ino +++ b/examples/MatrixExample1/MatrixExample1.ino @@ -2,7 +2,7 @@ #include // Change the next defines to match your matrix type and size -#define DATA_PIN D5 +#define DATA_PIN GPIO14 #define COLOR_ORDER GRB #define CHIPSET WS2812B From bc37fd57e55f71a1ab82d31d1fad126548214ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:19:01 +0100 Subject: [PATCH 23/35] change pins to ESP8266 generic --- examples/MatrixTilesExample/MatrixTilesExample.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino index 274c004..54ff6c6 100644 --- a/examples/MatrixTilesExample/MatrixTilesExample.ino +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -2,10 +2,10 @@ #include // 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 DATA_PIN GPIO4 +#define CLOCK_PIN GPIO5 +#define DATA2_PIN GPIO2 +#define CLOCK2_PIN GPIO0 #define COLOR_ORDER BGR #define CHIPSET APA102 From b034fd6d6bb081a1659ef82c461a08079a9eb610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:22:01 +0100 Subject: [PATCH 24/35] Update MatrixTilesExample.ino --- examples/MatrixTilesExample/MatrixTilesExample.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino index 54ff6c6..2da2907 100644 --- a/examples/MatrixTilesExample/MatrixTilesExample.ino +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -2,10 +2,10 @@ #include // Change the next defines to match your matrix type and size -#define DATA_PIN GPIO4 -#define CLOCK_PIN GPIO5 -#define DATA2_PIN GPIO2 -#define CLOCK2_PIN GPIO0 +#define DATA_PIN 4 +#define CLOCK_PIN 5 +#define DATA2_PIN 2 +#define CLOCK2_PIN 0 #define COLOR_ORDER BGR #define CHIPSET APA102 From 09813ec4efa4ed0b0b363827464c67f014499edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:22:15 +0100 Subject: [PATCH 25/35] Update MatrixExample1.ino --- examples/MatrixExample1/MatrixExample1.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MatrixExample1/MatrixExample1.ino b/examples/MatrixExample1/MatrixExample1.ino index 5817517..acf213e 100644 --- a/examples/MatrixExample1/MatrixExample1.ino +++ b/examples/MatrixExample1/MatrixExample1.ino @@ -2,7 +2,7 @@ #include // Change the next defines to match your matrix type and size -#define DATA_PIN GPIO14 +#define DATA_PIN 14 #define COLOR_ORDER GRB #define CHIPSET WS2812B From 155dc6fb2b47b41b4df986fddefe584f6e7d3f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:43:10 +0100 Subject: [PATCH 26/35] update github link on includes --- examples/MatrixExample1/MatrixExample1.ino | 14 +++++++------- examples/MatrixTilesExample/MatrixTilesExample.ino | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/MatrixExample1/MatrixExample1.ino b/examples/MatrixExample1/MatrixExample1.ino index acf213e..1d75882 100644 --- a/examples/MatrixExample1/MatrixExample1.ino +++ b/examples/MatrixExample1/MatrixExample1.ino @@ -1,5 +1,5 @@ -#include -#include +#include //https://github.com/FastLED/FastLED +#include //https://github.com/Jorgen-VikingGod/LEDMatrix // Change the next defines to match your matrix type and size #define DATA_PIN 14 @@ -8,11 +8,11 @@ #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 +#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 leds; diff --git a/examples/MatrixTilesExample/MatrixTilesExample.ino b/examples/MatrixTilesExample/MatrixTilesExample.ino index 2da2907..8486778 100644 --- a/examples/MatrixTilesExample/MatrixTilesExample.ino +++ b/examples/MatrixTilesExample/MatrixTilesExample.ino @@ -1,5 +1,5 @@ -#include -#include +#include //https://github.com/FastLED/FastLED +#include //https://github.com/Jorgen-VikingGod/LEDMatrix // Change the next defines to match your matrix type and size #define DATA_PIN 4 From e1964fff5db02a61c37ef90124be008ba2a2053e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Skrotzky?= Date: Fri, 18 Nov 2016 16:46:44 +0100 Subject: [PATCH 27/35] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index da8711d..7279b84 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![Travis build](https://img.shields.io/travis/Jorgen-VikingGod/LEDMatrix.svg)](https://travis-ci.org/Jorgen-VikingGod/LEDMatrix) [![GitHub version](https://img.shields.io/github/release/Jorgen-VikingGod/LEDMatrix.svg)](https://github.com/Jorgen-VikingGod/LEDMatrix/releases/latest) [![FastLED dependencies](https://img.shields.io/badge/dependencies-FastLED-blue.svg)](https://github.com/FastLED/FastLED) -[![FastLED-GFX dependencies](https://img.shields.io/badge/dependencies-FastLED--GFX-456789.svg)](https://github.com/Jorgen-VikingGod/FastLED-GFX) > A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and build in some features from ([Adafruit-NeoMatrix](https://github.com/adafruit/Adafruit_NeoMatrix)) From 3e52692cc86bd54071ac501807c90a1eda447d8a Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 29 Apr 2018 22:14:45 -0700 Subject: [PATCH 28/35] Update README.md Added link to https://github.com/marcmerlin/FastLED_NeoMatrix as an alternative to this library --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7279b84..1bf9343 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ > A fork of ([cLEDMatrix](https://github.com/AaronLiddiment/LEDMatrix) by [Aaron Liddiment](https://github.com/AaronLiddiment)) and build in some features from ([Adafruit-NeoMatrix](https://github.com/adafruit/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". From 9bbfa0fb1d530a2cb9f2c96b0f22f558d97a0989 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Fri, 4 May 2018 13:12:02 -0700 Subject: [PATCH 29/35] Fix division by 0 on single point draw, add DrawPixel. --- LEDMatrix.cpp | 28 ++++++++++++++++++---------- LEDMatrix.h | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/LEDMatrix.cpp b/LEDMatrix.cpp index c29655a..1676798 100755 --- a/LEDMatrix.cpp +++ b/LEDMatrix.cpp @@ -145,6 +145,9 @@ void cLEDMatrixBase::QuadrantBottomTriangleMirror() QuadrantMirror(); } +void cLEDMatrixBase::DrawPixel(int16_t x, int16_t y, CRGB Col) { + DrawLine(x, y, x, y, Col); +} void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) { @@ -152,17 +155,22 @@ void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CR int16_t dy = y1 - y0; if (abs(dx) >= abs(dy)) { - int32_t f = ((int32_t)dy << 16) / (int32_t)abs(dx); int32_t y = ((int32_t)y0 << 16) + 32768; - if (dx >= 0) - { - for (; x0<=x1; ++x0,y+=f) - (*this)(x0, (y >> 16)) = Col; - } - else - { - for (; x0>=x1; --x0,y+=f) - (*this)(x0, (y >> 16)) = Col; + // Support a single dot line without diving by 0 and crashing below + if (!dx) { + (*this)(x0, (y >> 16)) = Col; + } else { + int32_t f = ((int32_t)dy << 16) / (int32_t)abs(dx); + if (dx >= 0) + { + for (; x0<=x1; ++x0,y+=f) + (*this)(x0, (y >> 16)) = Col; + } + else + { + for (; x0>=x1; --x0,y+=f) + (*this)(x0, (y >> 16)) = Col; + } } } else diff --git a/LEDMatrix.h b/LEDMatrix.h index 1c3fc2d..8807800 100644 --- a/LEDMatrix.h +++ b/LEDMatrix.h @@ -48,6 +48,7 @@ class cLEDMatrixBase void QuadrantTopTriangleMirror(); void QuadrantBottomTriangleMirror(); + void DrawPixel(int16_t x, int16_t y, CRGB Col); void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); void DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); void DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col); From 32ee1e2804338e0f5d89e20c162008878688993b Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Fri, 4 May 2018 13:12:02 -0700 Subject: [PATCH 30/35] Fix division by 0 on single point draw, add DrawPixel. --- LEDMatrix.cpp | 28 ++++++++++++++++++---------- LEDMatrix.h | 1 + README.md | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/LEDMatrix.cpp b/LEDMatrix.cpp index c29655a..1676798 100755 --- a/LEDMatrix.cpp +++ b/LEDMatrix.cpp @@ -145,6 +145,9 @@ void cLEDMatrixBase::QuadrantBottomTriangleMirror() QuadrantMirror(); } +void cLEDMatrixBase::DrawPixel(int16_t x, int16_t y, CRGB Col) { + DrawLine(x, y, x, y, Col); +} void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col) { @@ -152,17 +155,22 @@ void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CR int16_t dy = y1 - y0; if (abs(dx) >= abs(dy)) { - int32_t f = ((int32_t)dy << 16) / (int32_t)abs(dx); int32_t y = ((int32_t)y0 << 16) + 32768; - if (dx >= 0) - { - for (; x0<=x1; ++x0,y+=f) - (*this)(x0, (y >> 16)) = Col; - } - else - { - for (; x0>=x1; --x0,y+=f) - (*this)(x0, (y >> 16)) = Col; + // Support a single dot line without diving by 0 and crashing below + if (!dx) { + (*this)(x0, (y >> 16)) = Col; + } else { + int32_t f = ((int32_t)dy << 16) / (int32_t)abs(dx); + if (dx >= 0) + { + for (; x0<=x1; ++x0,y+=f) + (*this)(x0, (y >> 16)) = Col; + } + else + { + for (; x0>=x1; --x0,y+=f) + (*this)(x0, (y >> 16)) = Col; + } } } else diff --git a/LEDMatrix.h b/LEDMatrix.h index 1c3fc2d..8807800 100644 --- a/LEDMatrix.h +++ b/LEDMatrix.h @@ -48,6 +48,7 @@ class cLEDMatrixBase void QuadrantTopTriangleMirror(); void QuadrantBottomTriangleMirror(); + void DrawPixel(int16_t x, int16_t y, CRGB Col); void DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); void DrawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col); void DrawCircle(int16_t xc, int16_t yc, uint16_t r, CRGB Col); diff --git a/README.md b/README.md index 7279b84..d1533da 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ 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) From fbcbd5303414d1c7fba22ec748baf50f23e71dcb Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Fri, 4 May 2018 14:41:06 -0700 Subject: [PATCH 31/35] Improve documentation to show reversed order Show both reverse order matrices and reverse order tiling --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7279b84..06f6fca 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,11 @@ Once you have downloaded the Zip file, it should be extracted into your Arduino ## Single Matrix ([Example](examples/MatrixExample1/MatrixExample1.ino)) ---------------------------------------------------------------- ### Parameters -| Parameter | Description | -| ------------ |---------------------------------------------| -| Parameter 1 | width of matrix | -| Parameter 2 | height of matrix | -| Parameter 3 | MatrixType_t = matrix layout type | +| 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 | ```c enum MatrixType_t { HORIZONTAL_MATRIX, @@ -73,7 +73,7 @@ enum BlockType_t { HORIZONTAL_BLOCKS, #include ``` -### Decleration +### Declaration ```c // Change the next defines to match your matrix type and size #define DATA_PIN D5 @@ -89,7 +89,8 @@ enum BlockType_t { HORIZONTAL_BLOCKS, #define NUMPIXELS MATRIX_SIZE // create our matrix based on matrix definition -cLEDMatrix leds; +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 @@ -133,7 +134,7 @@ enum BlockType_t { HORIZONTAL_BLOCKS, #include ``` -### Decleration +### Declaration ```c // Change the next defines to match your matrix type and size #define DATA_PIN D2 @@ -146,8 +147,8 @@ enum BlockType_t { HORIZONTAL_BLOCKS, #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 -#define MATRIX_TILE_V 8 // number of matrices arranged vertically +#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) @@ -157,7 +158,7 @@ enum BlockType_t { HORIZONTAL_BLOCKS, #define NUM_LEDS (MATRIX_WIDTH*MATRIX_HEIGHT) // create our matrix based on matrix definition -cLEDMatrix leds; +cLEDMatrix<[-]MATRIX_TILE_WIDTH, [-]MATRIX_TILE_HEIGHT, HORIZONTAL_ZIGZAG_MATRIX, [-]MATRIX_TILE_H, [-]MATRIX_TILE_V, VERTICAL_BLOCKS> leds; ``` ### Initialize FastLED From fdf2cf32ed76d07da89638d144c3239cf92fadac Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 3 Jan 2019 07:45:58 -0800 Subject: [PATCH 32/35] Added pointer to SmartMatrix::GFX to run LEDMatrix code on RGB Panels --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8e1546b..58b04be 100644 --- a/README.md +++ b/README.md @@ -216,3 +216,8 @@ 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. From 715bcfcfa5c618700a8f6763ed3eb6a75a4a5664 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sat, 6 Apr 2019 22:09:07 -0700 Subject: [PATCH 33/35] Added support for using an externally allocated memory array. This is used by SmartMatrix::GFX zero copy and saves considerable memory on larger arrays when using SmartMatrix. See https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/commit/e16c373cd95f7429c5e2a186826abaf0887887e0 --- LEDMatrix.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/LEDMatrix.h b/LEDMatrix.h index 8807800..ef21056 100644 --- a/LEDMatrix.h +++ b/LEDMatrix.h @@ -63,17 +63,29 @@ template 0))); static const int16_t m_absBWidth = (tBWidth * ((tBWidth < 0) * -1 + (tBWidth > 0))); static const int16_t m_absBHeight = (tBHeight * ((tBHeight < 0) * -1 + (tBHeight > 0))); - struct CRGB p_LED[m_absMWidth * m_absBWidth * m_absMHeight * m_absBHeight]; + struct CRGB *p_LED; public: - cLEDMatrix() + cLEDMatrix(bool doMalloc=true) { m_Width = m_absMWidth * m_absBWidth; m_Height = m_absMHeight * m_absBHeight; - m_LED = p_LED; + if (doMalloc) { + // On ESP32, there is more memory available via malloc than static global arrays + p_LED = (struct CRGB *) malloc(m_absMWidth * m_absBWidth * m_absMHeight * m_absBHeight * sizeof(CRGB)); + m_LED = p_LED; + if (! p_LED) { + Serial.begin(115200); + Serial.println("Malloc LEDMatrix Failed"); + while (1); + } + } else { + Serial.println("LED array not intialized, must be set by SetLEDArray"); + } } void SetLEDArray(struct CRGB *pLED) { + p_LED = pLED; m_LED = pLED; } virtual uint16_t mXY(uint16_t x, uint16_t y) From 45e86680ad0174438c80618948745a929a41ef58 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 26 Jan 2020 07:49:09 -0800 Subject: [PATCH 34/35] Support Matrices with more than 32K pixels. height and width can be bigger than 256 (ILI3941 is 320x240). If the array is bigger than 32K, signed pointers in the 1D array got negative and crashed the code. Similarly mXY multiplies 2 uint16_t, so it should be uint32_t. --- LEDMatrix.h | 120 ++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/LEDMatrix.h b/LEDMatrix.h index ef21056..9bed13a 100644 --- a/LEDMatrix.h +++ b/LEDMatrix.h @@ -28,7 +28,7 @@ class cLEDMatrixBase public: cLEDMatrixBase(); - virtual uint16_t mXY(uint16_t x, uint16_t y)=0; + virtual uint32_t mXY(uint16_t x, uint16_t y)=0; void SetLEDArray(struct CRGB *pLED); // Only used with externally defined LED arrays struct CRGB *operator[](int n); @@ -88,7 +88,7 @@ template0; --y,++i) { - for (int16_t x=m_absMWidth-1; x>0; --x,++i) + for (uint16_t x=m_absMWidth-1; x>0; --x,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); } } void HNWSL(void) { - int16_t i = m_absMWidth - 1; + uint32_t i = m_absMWidth - 1; for (int16_t y=m_absMHeight; y>0; --y) { - for (int16_t x=m_absMWidth-1; x>0; --x,--i) + for (uint16_t x=m_absMWidth-1; x>0; --x,--i) p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); i += ((m_absMWidth * 2) - 1); @@ -383,9 +383,9 @@ template0; --x) + uint32_t i = 0; + uint32_t j = m_absMHeight; + for (uint16_t x=m_absMWidth-1; x>0; --x) { for (int16_t y=m_absMHeight; y>0; --y) p_LED[i++] = p_LED[j++]; @@ -395,9 +395,9 @@ template0; --x) + uint32_t i = (m_absMHeight * m_absMWidth) - 1; + uint32_t j = i - m_absMHeight; + for (uint16_t x=m_absMWidth-1; x>0; --x) { for (int16_t y=m_absMHeight; y>0; --y) p_LED[i--] = p_LED[j--]; @@ -407,17 +407,17 @@ template0; y-=2) { - for (int16_t x=m_absMWidth-1; x>0; --x,++i) + for (uint16_t x=m_absMWidth-1; x>0; --x,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); i++; if (y > 1) { i += (m_absMWidth - 1); - for (int16_t x=m_absMWidth-1; x>0; --x,--i) + for (uint16_t x=m_absMWidth-1; x>0; --x,--i) p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); i += m_absMWidth; @@ -426,16 +426,16 @@ template0; y-=2) { - for (int16_t x=m_absMWidth-1; x>0; --x,--i) + for (uint16_t x=m_absMWidth-1; x>0; --x,--i) p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); if (y > 1) { i += m_absMWidth; - for (int16_t x=m_absMWidth-1; x>0; --x,++i) + for (uint16_t x=m_absMWidth-1; x>0; --x,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); i += m_absMWidth; @@ -444,9 +444,9 @@ template0; x-=2) + uint32_t i = 0; + uint32_t j = (m_absMHeight * 2) - 1; + for (uint16_t x=m_absMWidth-1; x>0; x-=2) { for (int16_t y=m_absMHeight; y>0; --y) p_LED[i++] = p_LED[j--]; @@ -463,9 +463,9 @@ template0; x-=2) + uint32_t i = (m_absMHeight * m_absMWidth) - 1; + uint32_t j = m_absMHeight * (m_absMWidth - 2); + for (uint16_t x=m_absMWidth-1; x>0; x-=2) { for (int16_t y=m_absMHeight; y>0; --y) p_LED[i--] = p_LED[j++]; @@ -484,44 +484,44 @@ template0; --y) + uint32_t i = 0; + uint32_t j = m_absMWidth; + for (uint16_t y=m_absMHeight-1; y>0; --y) { - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i++] = p_LED[j++]; } - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i++] = CRGB(0, 0, 0); } void HNHSD(void) { - int16_t i = (m_absMWidth * m_absMHeight) - 1; - int16_t j = i - m_absMWidth; - for (int16_t y=m_absMHeight-1; y>0; --y) + uint32_t i = (m_absMWidth * m_absMHeight) - 1; + uint32_t j = i - m_absMWidth; + for (uint16_t y=m_absMHeight-1; y>0; --y) { - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i--] = p_LED[j--]; } - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i--] = CRGB(0, 0, 0); } void VPHSD(void) { - int16_t i = 0; - for (int16_t x=m_absMWidth; x>0; --x,++i) + uint32_t i = 0; + for (uint16_t x=m_absMWidth; x>0; --x,++i) { - for (int16_t y=m_absMHeight-1; y>0; --y,++i) + for (uint16_t y=m_absMHeight-1; y>0; --y,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); } } void VNHSD(void) { - int16_t i = m_absMHeight - 1; - for (int16_t x=m_absMWidth; x>0; --x) + uint32_t i = m_absMHeight - 1; + for (uint16_t x=m_absMWidth; x>0; --x) { - for (int16_t y=m_absMHeight-1; y>0; --y,--i) + for (uint16_t y=m_absMHeight-1; y>0; --y,--i) p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); i += ((m_absMHeight * 2) - 1); @@ -529,55 +529,55 @@ template0; y-=2) + uint32_t i = 0; + uint32_t j = (m_absMWidth * 2) - 1; + for (uint16_t y=m_absMHeight-1; y>0; y-=2) { - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i++] = p_LED[j--]; if (y > 1) { j += (m_absMWidth * 2); - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i++] = p_LED[j--]; j += (m_absMWidth * 2); } } - for (int16_t x=m_absMWidth; x>0; x--) + for (uint16_t x=m_absMWidth; x>0; x--) p_LED[i++] = CRGB(0, 0, 0); } void HZNHSD(void) { - int16_t i = (m_absMWidth * m_absMHeight) - 1; - int16_t j = m_absMWidth * (m_absMHeight - 2); - for (int16_t y=m_absMHeight-1; y>0; y-=2) + uint32_t i = (m_absMWidth * m_absMHeight) - 1; + uint32_t j = m_absMWidth * (m_absMHeight - 2); + for (uint16_t y=m_absMHeight-1; y>0; y-=2) { - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i--] = p_LED[j++]; if (y > 1) { j -= (m_absMWidth * 2); - for (int16_t x=m_absMWidth; x>0; --x) + for (uint16_t x=m_absMWidth; x>0; --x) p_LED[i--] = p_LED[j++]; j -= (m_absMWidth * 2); } } - for (int16_t x=m_absMWidth; x>0; x--) + for (uint16_t x=m_absMWidth; x>0; x--) p_LED[i--] = CRGB(0, 0, 0); } void VZPHSD(void) { - int16_t i = 0; - for (int16_t x=m_absMWidth; x>0; x-=2) + uint32_t i = 0; + for (uint16_t x=m_absMWidth; x>0; x-=2) { - for (int16_t y=m_absMHeight-1; y>0; --y,++i) + for (uint16_t y=m_absMHeight-1; y>0; --y,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); i++; if (x > 1) { i += (m_absMHeight - 1); - for (int16_t y=m_absMHeight-1; y>0; --y,--i) + for (uint16_t y=m_absMHeight-1; y>0; --y,--i) p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); i += m_absMHeight; @@ -586,16 +586,16 @@ template0; x-=2) + uint32_t i = m_absMHeight - 1; + for (uint16_t x=m_absMWidth; x>0; x-=2) { - for (int16_t y=m_absMHeight-1; y>0; --y,--i) + for (uint16_t y=m_absMHeight-1; y>0; --y,--i) p_LED[i] = p_LED[i - 1]; p_LED[i] = CRGB(0, 0, 0); if (x > 1) { i += m_absMHeight; - for (int16_t y=m_absMHeight-1; y>0; --y,++i) + for (uint16_t y=m_absMHeight-1; y>0; --y,++i) p_LED[i] = p_LED[i + 1]; p_LED[i] = CRGB(0, 0, 0); i += m_absMHeight; From 4a668d2ddead159195a597a606c9b994909d5c33 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Sun, 26 Jan 2020 18:01:09 -0800 Subject: [PATCH 35/35] More info on how to run/debug LEDMatrix code on linux This allows for faster development/debugging. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index b061221..1980a91 100644 --- a/README.md +++ b/README.md @@ -223,3 +223,14 @@ void DrawFilledCircle(int16_t xc, int16_t yc, uint16_t r, CRGB color) 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: +- https://github.com/marcmerlin/ArduinoOnPc-FastLED-GFX-LEDMatrix +- https://github.com/marcmerlin/Framebuffer_GFX is the base arduino framebuffer that also supports more 2D arduino code in addition to Adafruit::GFX, including code that uses LEDMatrix. +- https://github.com/marcmerlin/FastLED_TFTWrapper_GFX is the driver that bridges that framebuffer with X11 (LINUX_RENDERER_X11) and the APIs it supports (FastLED, Adafruit::GFX, and LEDMatrix), with rpi-rgb-led-matrix for display. The other option is to use the faster LINUX_RENDERER_SDL which emulates FastLED and allows running native FastLED::NeoMatrix