Skip to content

Commit 61f7fe7

Browse files
authored
feat: use matrix library (#1)
1 parent 9189346 commit 61f7fe7

File tree

6 files changed

+127
-249
lines changed

6 files changed

+127
-249
lines changed

examples/air-quality-monitoring/sketch/air_quality_frames.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,50 @@
55
*/
66

77
const uint32_t good[] = {
8-
0x904101f0,
9-
0x5f420212,
10-
0x41390a28,
11-
0x10,
8+
0x0f808209,
9+
0x484042fa,
10+
0x14509c82,
11+
0x08000000,
1212
};
1313

1414
const uint32_t moderate[] = {
15-
0x904101f0,
16-
0x51420212,
17-
0x808209c8,
18-
0xf,
15+
0x0f808209,
16+
0x4840428a,
17+
0x13904101,
18+
0xf0000000,
1919
};
2020

2121
const uint32_t unhealthy_for_sensitive_groups[] = {
22-
0x904101f0,
23-
0x5f420212,
24-
0x80820808,
25-
0xf,
22+
0x0f808209,
23+
0x484042fa,
24+
0x10104101,
25+
0xf0000000,
2626
};
2727

2828
const uint32_t unhealthy[] = {
29-
0x904101f0,
30-
0x4e420212,
31-
0xc1010a28,
32-
0x1f,
29+
0x0f808209,
30+
0x48404272,
31+
0x14508083,
32+
0xf8000000,
3333
};
3434

3535
const uint32_t very_unhealthy[] = {
36-
0x904101f0,
37-
0x4042da12,
38-
0x808209c8,
39-
0xf,
36+
0x0f808209,
37+
0x485b4202,
38+
0x13904101,
39+
0xf0000000,
4040
};
4141

4242
const uint32_t hazardous[] = {
43-
0xd04101f0,
44-
0x44428a16,
45-
0x80540410,
46-
0xa,
43+
0x0f80820b,
44+
0x68514222,
45+
0x08202a01,
46+
0x50000000,
4747
};
4848

4949
const uint32_t unknown[] = {
50-
0x400c0000,
51-
0x4004002,
52-
0x40,
53-
0x1,
50+
0x00003002,
51+
0x40020020,
52+
0x02000000,
53+
0x80000000,
5454
};

examples/air-quality-monitoring/sketch/sketch.ino

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5+
#include <Arduino_LED_Matrix.h>
56
#include <Arduino_RouterBridge.h>
67

78
#include "air_quality_frames.h"
89

9-
// TODO: those will go into an header file.
10-
extern "C" void matrixWrite(const uint32_t* buf);
11-
extern "C" void matrixBegin();
10+
Arduino_LED_Matrix matrix;
1211

1312
void setup() {
14-
matrixBegin();
13+
matrix.begin();
14+
matrix.clear();
1515

16-
Bridge.begin();
16+
Bridge.begin();
1717
}
1818

1919
void loop() {
20-
String airQuality;
21-
bool ok = Bridge.call("get_air_quality").result(airQuality);
22-
if (ok) {
23-
if (airQuality == "Good") {
24-
matrixWrite(good);
25-
} else if (airQuality == "Moderate") {
26-
matrixWrite(moderate);
27-
} else if (airQuality == "Unhealthy for Sensitive Groups") {
28-
matrixWrite(unhealthy_for_sensitive_groups);
29-
} else if (airQuality == "Unhealthy") {
30-
matrixWrite(unhealthy);
31-
} else if (airQuality == "Very Unhealthy") {
32-
matrixWrite(very_unhealthy);
33-
} else if (airQuality == "Hazardous") {
34-
matrixWrite(hazardous);
35-
} else {
36-
matrixWrite(unknown);
37-
}
20+
String airQuality;
21+
bool ok = Bridge.call("get_air_quality").result(airQuality);
22+
if (ok) {
23+
if (airQuality == "Good") {
24+
matrix.loadFrame(good);
25+
} else if (airQuality == "Moderate") {
26+
matrix.loadFrame(moderate);
27+
} else if (airQuality == "Unhealthy for Sensitive Groups") {
28+
matrix.loadFrame(unhealthy_for_sensitive_groups);
29+
} else if (airQuality == "Unhealthy") {
30+
matrix.loadFrame(unhealthy);
31+
} else if (airQuality == "Very Unhealthy") {
32+
matrix.loadFrame(very_unhealthy);
33+
} else if (airQuality == "Hazardous") {
34+
matrix.loadFrame(hazardous);
35+
} else {
36+
matrix.loadFrame(unknown);
3837
}
39-
delay(1000);
38+
}
39+
delay(1000);
4040
}

examples/keyword-spotting/sketch/heart_frames.h

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,20 @@
44
* SPDX-License-Identifier: MPL-2.0
55
*/
66

7-
const uint32_t LittleHeart[] = {
8-
0x20360000,
9-
0x11010409,
10-
0x100140,
11-
0x0
7+
const uint32_t HeartStatic[4] = {
8+
0x00006c04,
9+
0x90208088,
10+
0x02800800,
11+
0x00000000,
12+
};
13+
14+
const uint32_t HeartAnim[][5] = {
15+
{0x1dc11108, 0x08404104, 0x04401400, 0x40000000, 55},
16+
{0x3fe31198, 0x0cc06306, 0x0c603600, 0xe0000000, 55},
17+
{0x3fe31198, 0x0cc06306, 0x0c603600, 0xe0000000, 55},
18+
{0x7ff711f8, 0x0fc07707, 0x1c707701, 0xf0000000, 55},
19+
{0xffff11f8, 0x0fc07f07, 0xbc78f783, 0xf8000000, 55},
20+
{0xffff11f8, 0x0fc07f07, 0xfc7ff7ef, 0xfe000000, 55},
21+
{0xffff11f8, 0x0fc07f07, 0xfc7ff7ff, 0xff000000, 55},
22+
{0xffff11f8, 0x0fc07f07, 0xfc7ff7ff, 0xff000000, 55},
1223
};
13-
14-
const uint32_t* HeartStatic[] = { LittleHeart };
15-
16-
const uint32_t Heart1[] = {
17-
0x108883b8,
18-
0x20820210,
19-
0x280220,
20-
0x2
21-
};
22-
23-
const uint32_t Heart2[] = {
24-
0x1988c7fc,
25-
0x60c60330,
26-
0x6c0630,
27-
0x7
28-
};
29-
30-
const uint32_t Heart3[] = {
31-
0x1988c7fc,
32-
0x60c60330,
33-
0x6c0630,
34-
0x7
35-
};
36-
37-
const uint32_t Heart4[] = {
38-
0x1f88effe,
39-
0xe0ee03f0,
40-
0x80ee0e38,
41-
0xf
42-
};
43-
44-
const uint32_t Heart5[] = {
45-
0x1f88ffff,
46-
0xe0fe03f0,
47-
0xc1ef1e3d,
48-
0x1f
49-
};
50-
51-
const uint32_t Heart6[] = {
52-
0x1f88ffff,
53-
0xe0fe03f0,
54-
0xf7effe3f,
55-
0x7f
56-
};
57-
58-
const uint32_t Heart7[] = {
59-
0x1f88ffff,
60-
0xe0fe03f0,
61-
0xffeffe3f,
62-
0xff
63-
};
64-
65-
const uint32_t Heart8[] = {
66-
0x1f88ffff,
67-
0xe0fe03f0,
68-
0xffeffe3f,
69-
0xff
70-
};
71-
72-
const uint32_t* HeartAnim[] = { Heart1, Heart2, Heart3, Heart4, Heart5, Heart6, Heart7, Heart8 };

examples/keyword-spotting/sketch/sketch.ino

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,29 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5+
#include <Arduino_LED_Matrix.h>
56
#include <Arduino_RouterBridge.h>
6-
#include "heart_frames.h"
77

8-
// TODO: those will go into an header file.
9-
extern "C" void matrixWrite(const uint32_t* buf);
10-
extern "C" void matrixBegin();
8+
#include "heart_frames.h"
119

12-
bool awake = false;
10+
Arduino_LED_Matrix matrix;
1311

1412
void setup() {
15-
matrixBegin();
16-
playAnimation(HeartStatic, 1, 1, 2000);
17-
Bridge.begin();
18-
Bridge.provide("keyword_detected", wake_up);
19-
}
13+
matrix.begin();
14+
matrix.clear();
15+
matrix.loadFrame(HeartStatic);
2016

21-
void loop() {
22-
if (awake) {
23-
playAnimation(HeartAnim, 8, 1, 50);
24-
delay(1000);
25-
playAnimation(HeartStatic, 1, 1, 2000);
26-
awake = false;
27-
}
17+
Bridge.begin();
18+
Bridge.provide("keyword_detected", wake_up);
2819
}
2920

30-
void playAnimation(const uint32_t* frames[], int frameCount, int repeat, int frameDelay) {
31-
for (int r = 0; r < repeat; r++) {
32-
for (int i = 0; i < frameCount; i++) {
33-
matrixWrite(frames[i]);
34-
delay(frameDelay);
35-
}
36-
}
37-
}
21+
void loop() {}
3822

3923
void wake_up() {
40-
awake = true;
24+
matrix.loadSequence(HeartAnim);
25+
matrix.playSequence();
26+
27+
delay(1000);
28+
29+
matrix.loadFrame(HeartStatic);
4130
}

examples/weather-forecast/sketch/sketch.ino

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,47 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5+
#include <Arduino_LED_Matrix.h>
56
#include <Arduino_RouterBridge.h>
67

78
#include "weather_frames.h"
89

9-
// TODO: those will go into an header file.
10-
extern "C" void matrixWrite(const uint32_t* buf);
11-
extern "C" void matrixBegin();
10+
String city = "Turin";
11+
12+
Arduino_LED_Matrix matrix;
1213

1314
void setup() {
14-
matrixBegin();
15+
matrix.begin();
16+
matrix.clear();
1517

1618
Bridge.begin();
1719
}
1820

19-
void playAnimation(const uint32_t* frames[], int frameCount, int repeat, int frameDelay) {
20-
for (int r = 0; r < repeat; r++) {
21-
for (int i = 0; i < frameCount; i++) {
22-
matrixWrite(frames[i]);
23-
delay(frameDelay);
24-
}
25-
}
26-
}
27-
28-
String city = "Turin";
29-
3021
void loop() {
3122
String weather_forecast;
32-
bool ok = Bridge.call("get_weather_forecast", city).result(weather_forecast);
23+
bool ok = Bridge.call("get_weather_forecast", city).result(weather_forecast);
3324
if (ok) {
3425
if (weather_forecast == "sunny") {
35-
playAnimation(SunnyFrames, 2, 20, 500);
26+
matrix.loadSequence(sunny);
27+
playRepeat(10);
3628
} else if (weather_forecast == "cloudy") {
37-
playAnimation(CloudyFrames, 4, 20, 500);
29+
matrix.loadSequence(cloudy);
30+
playRepeat(10);
3831
} else if (weather_forecast == "rainy") {
39-
playAnimation(RainyFrames, 3, 16, 200);
32+
matrix.loadSequence(rainy);
33+
playRepeat(20);
4034
} else if (weather_forecast == "snowy") {
41-
playAnimation(SnowyFrames, 3, 5, 650);
35+
matrix.loadSequence(snowy);
36+
playRepeat(10);
4237
} else if (weather_forecast == "foggy") {
43-
playAnimation(FoggyFrames, 2, 5, 660);
38+
matrix.loadSequence(foggy);
39+
playRepeat(5);
4440
}
4541
}
4642
}
43+
44+
void playRepeat(int repeat_count) {
45+
for (int i = 0; i < repeat_count; i++) {
46+
matrix.playSequence();
47+
}
48+
}

0 commit comments

Comments
 (0)