forked from Jorgen-VikingGod/LEDMatrix
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MatrixTilesExample.ino
147 lines (131 loc) · 5.17 KB
/
MatrixTilesExample.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <FastLED.h> //https://github.com/FastLED/FastLED
#include <LEDMatrix.h> //https://github.com/Jorgen-VikingGod/LEDMatrix
// Change the next defines to match your matrix type and size
#define DATA_PIN 4
#define CLOCK_PIN 5
#define DATA2_PIN 2
#define CLOCK2_PIN 0
#define COLOR_ORDER BGR
#define CHIPSET APA102
#define MATRIX_TILE_WIDTH 8 // width of EACH NEOPIXEL MATRIX (not total display)
#define MATRIX_TILE_HEIGHT 32 // height of each matrix
#define MATRIX_TILE_H 3 // number of matrices arranged horizontally
#define MATRIX_TILE_V 1 // 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_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_ZIGZAG_MATRIX, MATRIX_TILE_H, MATRIX_TILE_V, VERTICAL_BLOCKS> leds;
void matrix_clear() {
//FastLED[1].clearLedData();
// clear does not work properly with multiple matrices connected via parallel inputs
memset(leds[0], 0, NUM_LEDS*3);
}
void count_pixels() {
for (uint16_t i=0; i<MATRIX_HEIGHT; i++) {
Serial.print(i, HEX);
for (uint16_t j=0; j<MATRIX_WIDTH; j++) {
Serial.print(".");
leds.DrawPixel(j, i, i%3==0?CRGB::Blue:i%3==1?CRGB::Red:CRGB::Green);
// depending on the matrix size, it's too slow to display each pixel, so
// make the scan init faster. This will however be too fast on a small matrix.
#ifdef ESP8266
if (!(j%3)) FastLED.show();
yield(); // reset watchdog timer
#elif ESP32
delay(1);
FastLED.show();
#else
FastLED.show();
#endif
}
Serial.println("");
}
}
void setup()
{
delay(1000);
Serial.begin(115200);
//FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds[0], 0, leds.Size()/2).setCorrection(TypicalSMD5050);
//FastLED.addLeds<CHIPSET, DATA2_PIN, CLOCK2_PIN, COLOR_ORDER>(leds[0], leds.Size()/2, leds.Size()/2).setCorrection(TypicalSMD5050);
FastLED.addLeds<WS2811_PORTA,3>(leds[0], 256).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(32);
FastLED.clear(true);
matrix_clear();
#if 0
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);
matrix_clear();
#endif
count_pixels();
matrix_clear();
leds.DrawLine (0, 0, leds.Width() - 1, leds.Height() - 1, CRGB(0, 255, 0));
leds.DrawPixel(0, 0, CRGB(255, 0, 0));
leds.DrawPixel(leds.Width() - 1, leds.Height() - 1, CRGB(0, 0, 255));
FastLED.show();
Serial.println("Colors done");
delay(10000);
// 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);
Serial.println("Flag #1 done");
// 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);
Serial.println("Flag #2 done");
// 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();
delay(5000);
Serial.println("Flag #3 done");
}
void loop()
{
#if 0
uint8_t h = sin8(angle);
leds.ShiftLeft();
for (int16_t y=leds.Height()-1; y>=0; --y)
{
yield();
leds(leds.Width()-1, y) = CHSV(h, 255, 255);
h += 32;
}
angle += 4;
FastLED.show();
#endif
delay(20);
}