Skip to content

Commit a5e3800

Browse files
facchinmpillo79
authored andcommitted
unoq: add led matrix library
1 parent 6b18246 commit a5e3800

File tree

7 files changed

+6524
-0
lines changed

7 files changed

+6524
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include "ArduinoGraphics.h"
2+
#include "Arduino_LED_Matrix.h"
3+
4+
Arduino_LED_Matrix matrix;
5+
6+
void setup() {
7+
// put your setup code here, to run once:
8+
matrix.begin();
9+
matrix.textFont(Font_5x7);
10+
matrix.textScrollSpeed(100);
11+
matrix.clear();
12+
Serial.begin(115200);
13+
}
14+
15+
uint8_t shades[104] = {
16+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
19+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
20+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
21+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
22+
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
23+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
24+
};
25+
26+
const uint32_t animation[][5] = {
27+
{ 0x38022020,
28+
0x810408a0,
29+
0x2200e800,
30+
0x20000000,
31+
66 },
32+
{ 0x1c011010,
33+
0x40820450,
34+
0x11007400,
35+
0x10000000,
36+
66 },
37+
{ 0x0e008808,
38+
0x20410228,
39+
0x08803a00,
40+
0x08000000,
41+
66 },
42+
{ 0x07004404,
43+
0x10208114,
44+
0x04401d00,
45+
0x04000000,
46+
66 },
47+
{ 0x03802202,
48+
0x0810408a,
49+
0x02200e80,
50+
0x02000000,
51+
66 },
52+
{ 0x01c01101,
53+
0x04082045,
54+
0x01100740,
55+
0x01000000,
56+
66 },
57+
{ 0x00e00880,
58+
0x82041022,
59+
0x808803a0,
60+
0x00000000,
61+
66 },
62+
{ 0x00700440,
63+
0x40020011,
64+
0x004401c0,
65+
0x00000000,
66+
66 },
67+
{ 0x00380200,
68+
0x20010008,
69+
0x802000e0,
70+
0x00000000,
71+
66 },
72+
{ 0x00180100,
73+
0x10008004,
74+
0x00100060,
75+
0x00000000,
76+
66 },
77+
{ 0x00080080,
78+
0x08004002,
79+
0x00080020,
80+
0x00000000,
81+
66 },
82+
{ 0x00000040,
83+
0x04002001,
84+
0x00040000,
85+
0x00000000,
86+
66 },
87+
{ 0x00000000,
88+
0x02001000,
89+
0x80000000,
90+
0x00000000,
91+
66 },
92+
{ 0x00000000,
93+
0x00000000,
94+
0x00000000,
95+
0x00000000,
96+
66 }
97+
};
98+
99+
void loop() {
100+
// Roll a string using ArduinoGraphics
101+
matrix.beginText(0, 0, 127, 0, 0); // X, Y, then R, G, B
102+
matrix.print(" arduino.cc/uno-q ");
103+
matrix.endText(SCROLL_LEFT);
104+
delay(1000);
105+
// Draw shades
106+
matrix.setGrayscaleBits(3);
107+
matrix.draw(shades);
108+
delay(1000);
109+
matrix.clear();
110+
// Play an animation
111+
matrix.loadSequence(animation);
112+
for (int i = 0; i < 10; i++) {
113+
matrix.playSequence();
114+
}
115+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "bootanimation.h"
2+
#include "ArduinoGraphics.h"
3+
#include "Arduino_LED_Matrix.h"
4+
#include <zephyr/storage/flash_map.h>
5+
6+
Arduino_LED_Matrix matrix;
7+
8+
bool ok = false;
9+
10+
void setup() {
11+
12+
Serial.begin(115200);
13+
matrix.begin();
14+
matrix.textFont(Font_5x7);
15+
matrix.setGrayscaleBits(8);
16+
17+
// Before flashing, show the animation
18+
for (int i = 0; i < 2; i++) {
19+
matrix.playVideo(bootanimation.buf_loop, bootanimation.len_loop);
20+
}
21+
matrix.playVideo((uint8_t*)(bootanimation.buf_loop + bootanimation.len_loop), bootanimation.len_end);
22+
23+
const struct flash_area *fa;
24+
int rc;
25+
rc = flash_area_open(FIXED_PARTITION_ID(bootanimation), &fa);
26+
if (rc) {
27+
return;
28+
}
29+
30+
// flash the bootanimation header
31+
rc = flash_area_erase(fa, 0, fa->fa_size);
32+
if (rc) {
33+
return;
34+
}
35+
int header_len = sizeof(bootanimation) - sizeof(char*);
36+
rc = flash_area_write(fa, 0, &bootanimation, header_len);
37+
if (rc) {
38+
return;
39+
}
40+
rc = flash_area_write(fa, header_len, bootanimation.buf_loop, bootanimation.len_loop + bootanimation.len_end);
41+
if (rc) {
42+
return;
43+
}
44+
uint32_t flash_area[256];
45+
flash_area_read(fa, 0, flash_area, 256);
46+
Serial.println(flash_area[0], HEX);
47+
Serial.println(flash_area[1], HEX);
48+
Serial.println(flash_area[2], HEX);
49+
Serial.println(flash_area[3], HEX);
50+
Serial.println(flash_area[4], HEX);
51+
Serial.println(flash_area[5], HEX);
52+
ok = true;
53+
}
54+
55+
void loop() {
56+
matrix.beginText(0, 0, 127, 0, 0); // X, Y, then R, G, B
57+
if (ok) {
58+
matrix.print("OK :)");
59+
} else {
60+
matrix.print("KO :(");
61+
}
62+
matrix.endText();
63+
}

0 commit comments

Comments
 (0)