Skip to content

Commit 66985bf

Browse files
committed
update weather-forecast sketch
1 parent d72db04 commit 66985bf

File tree

2 files changed

+49
-111
lines changed

2 files changed

+49
-111
lines changed

examples/weather-forecast/sketch/sketch.ino

Lines changed: 28 additions & 26 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) {
34-
if (weather_forecast == "sunny") {
35-
playAnimation(SunnyFrames, 2, 20, 500);
36-
} else if (weather_forecast == "cloudy") {
37-
playAnimation(CloudyFrames, 4, 20, 500);
38-
} else if (weather_forecast == "rainy") {
39-
playAnimation(RainyFrames, 3, 16, 200);
40-
} else if (weather_forecast == "snowy") {
41-
playAnimation(SnowyFrames, 3, 5, 650);
42-
} else if (weather_forecast == "foggy") {
43-
playAnimation(FoggyFrames, 2, 5, 660);
25+
if ("sunny" == sequence_name) {
26+
matrix.loadSequence(Sunny);
27+
playRepeat(10);
28+
} else if ("cloudy" == sequence_name) {
29+
matrix.loadSequence(Cloudy);
30+
playRepeat(10);
31+
} else if ("rainy" == sequence_name) {
32+
matrix.loadSequence(Rainy);
33+
playRepeat(20);
34+
} else if ("snowy" == sequence_name) {
35+
matrix.loadSequence(Snowy);
36+
playRepeat(10);
37+
} else if ("foggy" == sequence_name) {
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+
}

examples/weather-forecast/sketch/weather_frames.h

Lines changed: 21 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,33 @@
44
* SPDX-License-Identifier: MPL-2.0
55
*/
66

7-
const uint32_t Sunny[] = {
8-
0xa0148120,
9-
0x9c1c801,
10-
0x409402c0,
11-
0x2
7+
const uint32_t Sunny[][5] = {
8+
{0x04812805, 0x80138390, 0x03402902, 0x40000000, 500},
9+
{0x12005201, 0xa072009c, 0x0b009400, 0x90000000, 500},
10+
{0x04812805, 0x80138390, 0x03402902, 0x40000000, 500},
1211
};
13-
const uint32_t Sunny2[] = {
14-
0x804a0048,
15-
0x39004e05,
16-
0x2900d0,
17-
0x9
18-
};
19-
const uint32_t* SunnyFrames[] = { Sunny, Sunny2 };
2012

21-
const uint32_t Cloudy[] = {
22-
0x701c0000,
23-
0x20211104,
24-
0x7f0404,
25-
0x0
26-
};
27-
const uint32_t Cloudy2[] = {
28-
0xe0380000,
29-
0x40422208,
30-
0xfe0808,
31-
0x0
32-
};
33-
const uint32_t Cloudy3[] = {
34-
0xc0700000,
35-
0x80844411,
36-
0x1fc1010,
37-
0x0
13+
const uint32_t Cloudy[][5] = {
14+
{0x0000380e, 0x20888404, 0x2020fe00, 0x00000000, 500},
15+
{0x00001c07, 0x10444202, 0x10107f00, 0x00000000, 500},
16+
{0x00000e03, 0x88222101, 0x08083f80, 0x00000000, 500},
17+
{0x00001c07, 0x10444202, 0x10107f00, 0x00000000, 500},
3818
};
39-
const uint32_t Cloudy4[] = {
40-
0xe0380000,
41-
0x40422208,
42-
0xfe0808,
43-
0x0
44-
};
45-
const uint32_t* CloudyFrames[] = { Cloudy, Cloudy2, Cloudy3, Cloudy4 };
4619

47-
const uint32_t Rainy[] = {
48-
0x104301e0,
49-
0x3f820210,
50-
0x8a0510,
51-
0x5
52-
};
53-
const uint32_t Rainy2[] = {
54-
0x104301e0,
55-
0x3f820210,
56-
0x40a20140,
57-
0x11
20+
const uint32_t Rainy[][5] = {
21+
{0x0780c208, 0x084041fc, 0x08a05100, 0xa0000000, 200},
22+
{0x0780c208, 0x084041fc, 0x02804502, 0x88000000, 200},
23+
{0x0780c208, 0x084041fc, 0x0a201402, 0x28000000, 200},
5824
};
59-
const uint32_t Rainy3[] = {
60-
0x104301e0,
61-
0x3f820210,
62-
0x40280450,
63-
0x14
64-
};
65-
const uint32_t* RainyFrames[] = { Rainy, Rainy2, Rainy3 };
6625

67-
const uint32_t Snowy[] = {
68-
0x104301e0,
69-
0x3f820210,
70-
0x220040,
71-
0x11
72-
};
73-
const uint32_t Snowy2[] = {
74-
0x104301e0,
75-
0x3f820210,
76-
0x40080400,
77-
0x4
78-
};
79-
const uint32_t Snowy3[] = {
80-
0x104301e0,
81-
0x3f820210,
82-
0x800110,
83-
0x1
26+
const uint32_t Snowy[][5] = {
27+
{0x0780c208, 0x084041fc, 0x02004400, 0x88000000, 650},
28+
{0x0780c208, 0x084041fc, 0x00201002, 0x20000000, 650},
29+
{0x0780c208, 0x084041fc, 0x08800100, 0x80000000, 650},
8430
};
85-
const uint32_t* SnowyFrames[] = { Snowy, Snowy2, Snowy3 };
8631

87-
const uint32_t Foggy[] = {
88-
0xdf8000,
89-
0x3f600,
90-
0xef8,
91-
0x0
32+
const uint32_t Foggy[][5] = {
33+
{0x0001fb00, 0x006fc000, 0x1f700000, 0x00000000, 660},
34+
{0x0001ef00, 0x0077c000, 0x1fb00000, 0x00000000, 660},
35+
{0x0001fb00, 0x006fc000, 0x1f700000, 0x00000000, 660},
9236
};
93-
const uint32_t Foggy2[] = {
94-
0xf78000,
95-
0x3ee00,
96-
0xdf8,
97-
0x0
98-
};
99-
100-
const uint32_t* FoggyFrames[] = { Foggy, Foggy2 };

0 commit comments

Comments
 (0)