LEDMatrix Library hinzugefügt

This commit is contained in:
Mario Voigt 2019-03-10 14:58:29 +01:00
parent 413c83b4cf
commit 8041429cb7
8 changed files with 1037 additions and 0 deletions

View File

@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

43
libraries/LEDMatrix-master/.gitignore vendored Normal file
View File

@ -0,0 +1,43 @@
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

View File

@ -0,0 +1,242 @@
/*
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 <FastLED.h>
#include <LEDMatrix.h>
cLEDMatrixBase::cLEDMatrixBase()
{
}
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))
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)))
return(m_LED[i]);
else
return(m_OutOfBounds);
}
void cLEDMatrixBase::HorizontalMirror(bool FullHeight)
{
int ty, y, x, xx;
if (FullHeight)
ty = m_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)
m_LED[mXY(xx, y)] = m_LED[mXY(x, y)];
}
}
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)
m_LED[mXY(x, yy)] = m_LED[mXY(x, y)];
}
}
void cLEDMatrixBase::QuadrantMirror()
{
HorizontalMirror(false);
VerticalMirror();
}
void cLEDMatrixBase::QuadrantRotateMirror()
{
int MaxXY, MidXY, x, y, src;
if (m_Width > m_Height)
MaxXY = m_Height;
else
MaxXY = m_Width;
MidXY = (MaxXY / 2);
MaxXY--;
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];
m_LED[mXY(MidXY - (MaxXY % 2) - y, MidXY + x)] = m_LED[src];
}
}
}
void cLEDMatrixBase::TriangleTopMirror(bool FullHeight)
{
int MaxXY, x, y;
if (m_Width > m_Height)
MaxXY = m_Height - 1;
else
MaxXY = m_Width - 1;
if (! FullHeight)
MaxXY /= 2;
for (y=1; y<=MaxXY; ++y)
{
for (x=0; x<y; ++x)
m_LED[mXY(y,x)] = m_LED[mXY(x,y)];
}
}
void cLEDMatrixBase::TriangleBottomMirror(bool FullHeight)
{
int MaxXY, x, y, xx, yy;
if (m_Width > m_Height)
MaxXY = m_Height - 1;
else
MaxXY = m_Width - 1;
if (! FullHeight)
MaxXY /= 2;
for (y=0,xx=MaxXY; y<MaxXY; y++,xx--)
{
for (x=MaxXY-y-1,yy=y+1; x>=0; --x,++yy)
m_LED[mXY(xx, yy)] = m_LED[mXY(x, y)];
}
}
void cLEDMatrixBase::QuadrantTopTriangleMirror()
{
TriangleTopMirror(false);
QuadrantMirror();
}
void cLEDMatrixBase::QuadrantBottomTriangleMirror()
{
TriangleBottomMirror(false);
QuadrantMirror();
}
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::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;
}
}

View File

@ -0,0 +1,509 @@
#ifndef LEDMatrix_h
#define LEDMatrix_h
enum MatrixType_t { HORIZONTAL_MATRIX,
VERTICAL_MATRIX,
HORIZONTAL_ZIGZAG_MATRIX,
VERTICAL_ZIGZAG_MATRIX };
class cLEDMatrixBase
{
friend class cSprite;
protected:
int16_t m_Width, m_Height;
MatrixType_t m_Type;
struct CRGB *m_LED;
struct CRGB m_OutOfBounds;
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
struct CRGB *operator[](int n);
struct CRGB &operator()(int16_t x, int16_t y);
struct CRGB &operator()(int16_t i);
int Size() { return(m_Width * m_Height); }
int Width() { return(m_Width); }
int Height() { return(m_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 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<int16_t tWidth, int16_t tHeight, MatrixType_t tMType, int16_t tXMult = 0, int16_t tYMult = 0> 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
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);
else
return((y * m_absWidth * tYMult) + (x * tXMult));
}
else if (tMType == VERTICAL_MATRIX)
{
if ((tXMult == 0) && (tYMult == 0))
return((x * m_absHeight) + y);
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));
}
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));
}
else
{
if ((tXMult == 0) && (tYMult == 0))
return((x * m_absHeight) + y);
else
return((x * m_absHeight * tXMult) + (y * tYMult));
}
}
}
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)
{
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)
{
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;
}
}
}
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);
}
}
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 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--] = 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;
}
}
}
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;
}
}
}
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--];
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--] = 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);
}
}
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++];
}
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--];
}
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 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--];
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--] = 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);
}
}
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 += 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];
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;
}
}
}
};
#endif

View File

@ -0,0 +1,3 @@
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.

View File

@ -0,0 +1,95 @@
#include <FastLED.h>
#include <LEDMatrix.h>
// 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_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
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
uint8_t hue;
int16_t counter;
void setup()
{
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(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);
hue = 0;
counter = 0;
}
void loop()
{
int16_t sx, sy, x, y;
uint8_t h;
FastLED.clear();
h = hue;
if (counter < 1125)
{
// ** Fill LED's with diagonal stripes
for (x=0; x<(leds.Width()+leds.Height()); ++x)
{
leds.DrawLine(x - leds.Height(), leds.Height() - 1, x, 0, CHSV(h, 255, 255));
h+=16;
}
}
else
{
// ** Fill LED's with horizontal stripes
for (y=0; y<leds.Height(); ++y)
{
leds.DrawLine(0, y, leds.Width() - 1, y, CHSV(h, 255, 255));
h+=16;
}
}
hue+=4;
if (counter < 125)
;
else if (counter < 375)
leds.HorizontalMirror();
else if (counter < 625)
leds.VerticalMirror();
else if (counter < 875)
leds.QuadrantMirror();
else if (counter < 1125)
leds.QuadrantRotateMirror();
else if (counter < 1250)
;
else if (counter < 1500)
leds.TriangleTopMirror();
else if (counter < 1750)
leds.TriangleBottomMirror();
else if (counter < 2000)
leds.QuadrantTopTriangleMirror();
else if (counter < 2250)
leds.QuadrantBottomTriangleMirror();
counter++;
if (counter >= 2250)
counter = 0;
FastLED.show();
}

View File

@ -0,0 +1,86 @@
#include <FastLED.h>
#include <LEDMatrix.h>
// 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_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
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
uint8_t angle = 0;
void setup()
{
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(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);
}

View File

@ -0,0 +1,42 @@
#######################################
# Syntax Coloring Map For LEDMatrix
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
cLEDMatrix KEYWORD1
cLEDMatrixBase KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
mXY KEYWORD2
Size KEYWORD2
Width KEYWORD2
Height KEYWORD2
HorizontalMirror KEYWORD2
VerticalMirror KEYWORD2
QuadrantMirror KEYWORD2
QuadrantRotateMirror KEYWORD2
TriangleTopMirror KEYWORD2
TriangleBottomMirror KEYWORD2
QuadrantTopTriangleMirror KEYWORD2
QuadrantBottomTriangleMirror KEYWORD2
DrawLine KEYWORD2
DrawRectangle KEYWORD2
DrawCircle KEYWORD2
DrawFilledRectangle KEYWORD2
DrawFilledCircle KEYWORD2
ShiftLeft KEYWORD2
ShiftRight KEYWORD2
ShiftDown KEYWORD2
ShiftUp KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
HORIZONTAL_MATRIX LITERAL1
VERTICAL_MATRIX LITERAL1
HORIZONTAL_ZIGZAG_MATRIX LITERAL1
VERTICAL_ZIGZAG_MATRIX LITERAL1