Skip to content

Commit 9120830

Browse files
authored
LedMatrix: new examples (#59)
1 parent b85f1ff commit 9120830

File tree

6 files changed

+186
-46
lines changed

6 files changed

+186
-46
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Arduino_LED_Matrix.h"
2+
#include "frames.h"
3+
4+
ArduinoLEDMatrix matrix;
5+
6+
void setup() {
7+
Serial.begin(115200);
8+
matrix.begin();
9+
}
10+
11+
void loop() {
12+
matrix.loadFrame(chip);
13+
delay(500);
14+
matrix.loadFrame(danger);
15+
delay(500);
16+
matrix.loadFrame(happy);
17+
delay(500);
18+
matrix.loadFrame(heart);
19+
delay(500);
20+
Serial.println(millis());
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const uint32_t chip[] = {
2+
0x1503f811,
3+
0x3181103,
4+
0xf8150000
5+
};
6+
7+
const uint32_t danger[] = {
8+
0x400a015,
9+
0x1502082,
10+
0x484047fc
11+
};
12+
13+
const uint32_t happy[] = {
14+
0x19819,
15+
0x80000001,
16+
0x81f8000
17+
};
18+
19+
const uint32_t heart[] = {
20+
0x3184a444,
21+
0x44042081,
22+
0x100a0040
23+
};
24+
25+
/*
26+
const uint32_t fullOn[] = {
27+
0xffffffff,
28+
0xffffffff,
29+
0xffffffff
30+
}
31+
*/
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "Arduino_LED_Matrix.h"
2+
ArduinoLEDMatrix matrix;
3+
4+
uint8_t frame[8][12] = {
5+
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
6+
{ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
7+
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
8+
{ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
9+
{ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
10+
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
11+
{ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
12+
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
13+
};
14+
15+
unsigned long lastTickTime, lastGameTickTime;
16+
#define UPDATE_INTERVAL 100
17+
#define GAME_UPDATE_INTERVAL 66
18+
19+
#define ROWS 8
20+
#define COLUMNS 12
21+
22+
uint8_t pointX = 0, pointY = 0;
23+
24+
void setup() {
25+
// put your setup code here, to run once:
26+
Serial.begin(115200);
27+
delay(1500);
28+
matrix.begin();
29+
lastGameTickTime = lastTickTime = millis();
30+
}
31+
32+
void loop() {
33+
unsigned long msNow = millis();
34+
if (msNow - lastGameTickTime > GAME_UPDATE_INTERVAL) {
35+
pointX++;
36+
if (pointX >= COLUMNS) {
37+
pointX = 0;
38+
pointY++;
39+
if (pointY >= ROWS) {
40+
pointY = 0;
41+
}
42+
}
43+
pointX = random(COLUMNS);
44+
pointY = random(ROWS);
45+
uint8_t pixelValue = random(2);
46+
frame[pointY][pointX] = pixelValue;
47+
lastGameTickTime = msNow;
48+
}
49+
if (msNow - lastTickTime > UPDATE_INTERVAL) {
50+
matrix.renderBitmap(frame, 8, 12);
51+
lastTickTime = msNow;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#include "LED_Matrix.h"
2-
#include "frames.h"
1+
#include "Arduino_LED_Matrix.h"
2+
#include "animation.h"
33

4-
LED_Matrix matrix;
4+
ArduinoLEDMatrix matrix;
55

66
void setup() {
77
Serial.begin(115200);
88
// you can also load frames at runtime, without stopping the refresh
9-
matrix.load(frames);
9+
matrix.loadSequence(animation);
1010
matrix.begin();
1111
// turn on autoscroll to avoid calling next() to show the next frame; the paramenter is in milliseconds
12-
matrix.autoscroll(300);
12+
// matrix.autoscroll(300);
13+
matrix.play(true);
1314
}
1415

1516
void loop() {
16-
// if autoscroll() was not called, user needs to call next() when needed
17-
// matrix.next();
18-
delay(1000);
17+
delay(500);
1918
Serial.println(millis());
2019
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const uint32_t animation[][4] = {
2+
{
3+
0x30c20,
4+
0x43fc3fc2,
5+
0x430c000,
6+
66
7+
},
8+
{
9+
0x30c29,
10+
0x436c36c2,
11+
0x9430c000,
12+
66
13+
},
14+
{
15+
0x30c2f,
16+
0x430c30c2,
17+
0xf430c000,
18+
66
19+
},
20+
{
21+
0x36c29,
22+
0x41081082,
23+
0x9436c000,
24+
66
25+
},
26+
{
27+
0x3fc30,
28+
0xc1081083,
29+
0xc3fc000,
30+
66
31+
},
32+
{
33+
0x3fc20,
34+
0x42042042,
35+
0x43fc000,
36+
66
37+
},
38+
{
39+
0x3f,
40+
0xc2042043,
41+
0xfc000000,
42+
66
43+
},
44+
{
45+
0x0,
46+
0x3fc3fc0,
47+
0x0,
48+
66
49+
},
50+
{
51+
0x0,
52+
0x1f81f80,
53+
0x0,
54+
66
55+
},
56+
{
57+
0x0,
58+
0xf00f00,
59+
0x0,
60+
66
61+
},
62+
{
63+
0x0,
64+
0x600600,
65+
0x0,
66+
66
67+
},
68+
{
69+
0x0,
70+
0x0,
71+
0x0,
72+
66
73+
}
74+
};

libraries/Arduino_LED_Matrix/examples/ShowFrames/frames.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)