diff --git a/examples/air-quality-monitoring/sketch/air_quality_frames.h b/examples/air-quality-monitoring/sketch/air_quality_frames.h index 18ddcab..fe5e635 100644 --- a/examples/air-quality-monitoring/sketch/air_quality_frames.h +++ b/examples/air-quality-monitoring/sketch/air_quality_frames.h @@ -5,50 +5,50 @@ */ const uint32_t good[] = { - 0x904101f0, - 0x5f420212, - 0x41390a28, - 0x10, + 0x0f808209, + 0x484042fa, + 0x14509c82, + 0x08000000, }; const uint32_t moderate[] = { - 0x904101f0, - 0x51420212, - 0x808209c8, - 0xf, + 0x0f808209, + 0x4840428a, + 0x13904101, + 0xf0000000, }; const uint32_t unhealthy_for_sensitive_groups[] = { - 0x904101f0, - 0x5f420212, - 0x80820808, - 0xf, + 0x0f808209, + 0x484042fa, + 0x10104101, + 0xf0000000, }; const uint32_t unhealthy[] = { - 0x904101f0, - 0x4e420212, - 0xc1010a28, - 0x1f, + 0x0f808209, + 0x48404272, + 0x14508083, + 0xf8000000, }; const uint32_t very_unhealthy[] = { - 0x904101f0, - 0x4042da12, - 0x808209c8, - 0xf, + 0x0f808209, + 0x485b4202, + 0x13904101, + 0xf0000000, }; const uint32_t hazardous[] = { - 0xd04101f0, - 0x44428a16, - 0x80540410, - 0xa, + 0x0f80820b, + 0x68514222, + 0x08202a01, + 0x50000000, }; const uint32_t unknown[] = { - 0x400c0000, - 0x4004002, - 0x40, - 0x1, + 0x00003002, + 0x40020020, + 0x02000000, + 0x80000000, }; diff --git a/examples/air-quality-monitoring/sketch/sketch.ino b/examples/air-quality-monitoring/sketch/sketch.ino index 57d4874..64eae23 100644 --- a/examples/air-quality-monitoring/sketch/sketch.ino +++ b/examples/air-quality-monitoring/sketch/sketch.ino @@ -2,39 +2,39 @@ // // SPDX-License-Identifier: MPL-2.0 +#include #include #include "air_quality_frames.h" -// TODO: those will go into an header file. -extern "C" void matrixWrite(const uint32_t* buf); -extern "C" void matrixBegin(); +Arduino_LED_Matrix matrix; void setup() { - matrixBegin(); + matrix.begin(); + matrix.clear(); - Bridge.begin(); + Bridge.begin(); } void loop() { - String airQuality; - bool ok = Bridge.call("get_air_quality").result(airQuality); - if (ok) { - if (airQuality == "Good") { - matrixWrite(good); - } else if (airQuality == "Moderate") { - matrixWrite(moderate); - } else if (airQuality == "Unhealthy for Sensitive Groups") { - matrixWrite(unhealthy_for_sensitive_groups); - } else if (airQuality == "Unhealthy") { - matrixWrite(unhealthy); - } else if (airQuality == "Very Unhealthy") { - matrixWrite(very_unhealthy); - } else if (airQuality == "Hazardous") { - matrixWrite(hazardous); - } else { - matrixWrite(unknown); - } + String airQuality; + bool ok = Bridge.call("get_air_quality").result(airQuality); + if (ok) { + if (airQuality == "Good") { + matrix.loadFrame(good); + } else if (airQuality == "Moderate") { + matrix.loadFrame(moderate); + } else if (airQuality == "Unhealthy for Sensitive Groups") { + matrix.loadFrame(unhealthy_for_sensitive_groups); + } else if (airQuality == "Unhealthy") { + matrix.loadFrame(unhealthy); + } else if (airQuality == "Very Unhealthy") { + matrix.loadFrame(very_unhealthy); + } else if (airQuality == "Hazardous") { + matrix.loadFrame(hazardous); + } else { + matrix.loadFrame(unknown); } - delay(1000); + } + delay(1000); } diff --git a/examples/keyword-spotting/sketch/heart_frames.h b/examples/keyword-spotting/sketch/heart_frames.h index d3ab988..7447e38 100644 --- a/examples/keyword-spotting/sketch/heart_frames.h +++ b/examples/keyword-spotting/sketch/heart_frames.h @@ -4,69 +4,20 @@ * SPDX-License-Identifier: MPL-2.0 */ -const uint32_t LittleHeart[] = { - 0x20360000, - 0x11010409, - 0x100140, - 0x0 +const uint32_t HeartStatic[4] = { + 0x00006c04, + 0x90208088, + 0x02800800, + 0x00000000, +}; + +const uint32_t HeartAnim[][5] = { + {0x1dc11108, 0x08404104, 0x04401400, 0x40000000, 55}, + {0x3fe31198, 0x0cc06306, 0x0c603600, 0xe0000000, 55}, + {0x3fe31198, 0x0cc06306, 0x0c603600, 0xe0000000, 55}, + {0x7ff711f8, 0x0fc07707, 0x1c707701, 0xf0000000, 55}, + {0xffff11f8, 0x0fc07f07, 0xbc78f783, 0xf8000000, 55}, + {0xffff11f8, 0x0fc07f07, 0xfc7ff7ef, 0xfe000000, 55}, + {0xffff11f8, 0x0fc07f07, 0xfc7ff7ff, 0xff000000, 55}, + {0xffff11f8, 0x0fc07f07, 0xfc7ff7ff, 0xff000000, 55}, }; - -const uint32_t* HeartStatic[] = { LittleHeart }; - -const uint32_t Heart1[] = { - 0x108883b8, - 0x20820210, - 0x280220, - 0x2 -}; - -const uint32_t Heart2[] = { - 0x1988c7fc, - 0x60c60330, - 0x6c0630, - 0x7 -}; - -const uint32_t Heart3[] = { - 0x1988c7fc, - 0x60c60330, - 0x6c0630, - 0x7 -}; - -const uint32_t Heart4[] = { - 0x1f88effe, - 0xe0ee03f0, - 0x80ee0e38, - 0xf -}; - -const uint32_t Heart5[] = { - 0x1f88ffff, - 0xe0fe03f0, - 0xc1ef1e3d, - 0x1f -}; - -const uint32_t Heart6[] = { - 0x1f88ffff, - 0xe0fe03f0, - 0xf7effe3f, - 0x7f -}; - -const uint32_t Heart7[] = { - 0x1f88ffff, - 0xe0fe03f0, - 0xffeffe3f, - 0xff -}; - -const uint32_t Heart8[] = { - 0x1f88ffff, - 0xe0fe03f0, - 0xffeffe3f, - 0xff -}; - -const uint32_t* HeartAnim[] = { Heart1, Heart2, Heart3, Heart4, Heart5, Heart6, Heart7, Heart8 }; \ No newline at end of file diff --git a/examples/keyword-spotting/sketch/sketch.ino b/examples/keyword-spotting/sketch/sketch.ino index b8cf7e9..16f373d 100644 --- a/examples/keyword-spotting/sketch/sketch.ino +++ b/examples/keyword-spotting/sketch/sketch.ino @@ -2,40 +2,29 @@ // // SPDX-License-Identifier: MPL-2.0 +#include #include -#include "heart_frames.h" -// TODO: those will go into an header file. -extern "C" void matrixWrite(const uint32_t* buf); -extern "C" void matrixBegin(); +#include "heart_frames.h" -bool awake = false; +Arduino_LED_Matrix matrix; void setup() { - matrixBegin(); - playAnimation(HeartStatic, 1, 1, 2000); - Bridge.begin(); - Bridge.provide("keyword_detected", wake_up); -} + matrix.begin(); + matrix.clear(); + matrix.loadFrame(HeartStatic); -void loop() { - if (awake) { - playAnimation(HeartAnim, 8, 1, 50); - delay(1000); - playAnimation(HeartStatic, 1, 1, 2000); - awake = false; - } + Bridge.begin(); + Bridge.provide("keyword_detected", wake_up); } -void playAnimation(const uint32_t* frames[], int frameCount, int repeat, int frameDelay) { - for (int r = 0; r < repeat; r++) { - for (int i = 0; i < frameCount; i++) { - matrixWrite(frames[i]); - delay(frameDelay); - } - } -} +void loop() {} void wake_up() { - awake = true; + matrix.loadSequence(HeartAnim); + matrix.playSequence(); + + delay(1000); + + matrix.loadFrame(HeartStatic); } diff --git a/examples/weather-forecast/sketch/sketch.ino b/examples/weather-forecast/sketch/sketch.ino index 7550f54..3e7ee3a 100644 --- a/examples/weather-forecast/sketch/sketch.ino +++ b/examples/weather-forecast/sketch/sketch.ino @@ -2,45 +2,47 @@ // // SPDX-License-Identifier: MPL-2.0 +#include #include #include "weather_frames.h" -// TODO: those will go into an header file. -extern "C" void matrixWrite(const uint32_t* buf); -extern "C" void matrixBegin(); +String city = "Turin"; + +Arduino_LED_Matrix matrix; void setup() { - matrixBegin(); + matrix.begin(); + matrix.clear(); Bridge.begin(); } -void playAnimation(const uint32_t* frames[], int frameCount, int repeat, int frameDelay) { - for (int r = 0; r < repeat; r++) { - for (int i = 0; i < frameCount; i++) { - matrixWrite(frames[i]); - delay(frameDelay); - } - } -} - -String city = "Turin"; - void loop() { String weather_forecast; - bool ok = Bridge.call("get_weather_forecast", city).result(weather_forecast); + bool ok = Bridge.call("get_weather_forecast", city).result(weather_forecast); if (ok) { if (weather_forecast == "sunny") { - playAnimation(SunnyFrames, 2, 20, 500); + matrix.loadSequence(sunny); + playRepeat(10); } else if (weather_forecast == "cloudy") { - playAnimation(CloudyFrames, 4, 20, 500); + matrix.loadSequence(cloudy); + playRepeat(10); } else if (weather_forecast == "rainy") { - playAnimation(RainyFrames, 3, 16, 200); + matrix.loadSequence(rainy); + playRepeat(20); } else if (weather_forecast == "snowy") { - playAnimation(SnowyFrames, 3, 5, 650); + matrix.loadSequence(snowy); + playRepeat(10); } else if (weather_forecast == "foggy") { - playAnimation(FoggyFrames, 2, 5, 660); + matrix.loadSequence(foggy); + playRepeat(5); } } } + +void playRepeat(int repeat_count) { + for (int i = 0; i < repeat_count; i++) { + matrix.playSequence(); + } +} diff --git a/examples/weather-forecast/sketch/weather_frames.h b/examples/weather-forecast/sketch/weather_frames.h index c479813..f2d4e10 100644 --- a/examples/weather-forecast/sketch/weather_frames.h +++ b/examples/weather-forecast/sketch/weather_frames.h @@ -4,97 +4,33 @@ * SPDX-License-Identifier: MPL-2.0 */ -const uint32_t Sunny[] = { - 0xa0148120, - 0x9c1c801, - 0x409402c0, - 0x2 +const uint32_t sunny[][5] = { + {0x04812805, 0x80138390, 0x03402902, 0x40000000, 500}, + {0x12005201, 0xa072009c, 0x0b009400, 0x90000000, 500}, + {0x04812805, 0x80138390, 0x03402902, 0x40000000, 500}, }; -const uint32_t Sunny2[] = { - 0x804a0048, - 0x39004e05, - 0x2900d0, - 0x9 -}; -const uint32_t* SunnyFrames[] = { Sunny, Sunny2 }; -const uint32_t Cloudy[] = { - 0x701c0000, - 0x20211104, - 0x7f0404, - 0x0 -}; -const uint32_t Cloudy2[] = { - 0xe0380000, - 0x40422208, - 0xfe0808, - 0x0 -}; -const uint32_t Cloudy3[] = { - 0xc0700000, - 0x80844411, - 0x1fc1010, - 0x0 +const uint32_t cloudy[][5] = { + {0x0000380e, 0x20888404, 0x2020fe00, 0x00000000, 500}, + {0x00001c07, 0x10444202, 0x10107f00, 0x00000000, 500}, + {0x00000e03, 0x88222101, 0x08083f80, 0x00000000, 500}, + {0x00001c07, 0x10444202, 0x10107f00, 0x00000000, 500}, }; -const uint32_t Cloudy4[] = { - 0xe0380000, - 0x40422208, - 0xfe0808, - 0x0 -}; -const uint32_t* CloudyFrames[] = { Cloudy, Cloudy2, Cloudy3, Cloudy4 }; -const uint32_t Rainy[] = { - 0x104301e0, - 0x3f820210, - 0x8a0510, - 0x5 -}; -const uint32_t Rainy2[] = { - 0x104301e0, - 0x3f820210, - 0x40a20140, - 0x11 +const uint32_t rainy[][5] = { + {0x0780c208, 0x084041fc, 0x08a05100, 0xa0000000, 200}, + {0x0780c208, 0x084041fc, 0x02804502, 0x88000000, 200}, + {0x0780c208, 0x084041fc, 0x0a201402, 0x28000000, 200}, }; -const uint32_t Rainy3[] = { - 0x104301e0, - 0x3f820210, - 0x40280450, - 0x14 -}; -const uint32_t* RainyFrames[] = { Rainy, Rainy2, Rainy3 }; -const uint32_t Snowy[] = { - 0x104301e0, - 0x3f820210, - 0x220040, - 0x11 -}; -const uint32_t Snowy2[] = { - 0x104301e0, - 0x3f820210, - 0x40080400, - 0x4 -}; -const uint32_t Snowy3[] = { - 0x104301e0, - 0x3f820210, - 0x800110, - 0x1 +const uint32_t snowy[][5] = { + {0x0780c208, 0x084041fc, 0x02004400, 0x88000000, 650}, + {0x0780c208, 0x084041fc, 0x00201002, 0x20000000, 650}, + {0x0780c208, 0x084041fc, 0x08800100, 0x80000000, 650}, }; -const uint32_t* SnowyFrames[] = { Snowy, Snowy2, Snowy3 }; -const uint32_t Foggy[] = { - 0xdf8000, - 0x3f600, - 0xef8, - 0x0 +const uint32_t foggy[][5] = { + {0x0001fb00, 0x006fc000, 0x1f700000, 0x00000000, 660}, + {0x0001ef00, 0x0077c000, 0x1fb00000, 0x00000000, 660}, + {0x0001fb00, 0x006fc000, 0x1f700000, 0x00000000, 660}, }; -const uint32_t Foggy2[] = { - 0xf78000, - 0x3ee00, - 0xdf8, - 0x0 -}; - -const uint32_t* FoggyFrames[] = { Foggy, Foggy2 };