From b70551bcf7cc15c9c6ef2d0df728a06495e1b0b9 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Tue, 28 Oct 2025 18:56:52 +0100 Subject: [PATCH 1/2] feat: use matrix library --- .../sketch/air_quality_frames.h | 56 +++++++++---------- .../air-quality-monitoring/sketch/sketch.ino | 48 ++++++++-------- 2 files changed, 52 insertions(+), 52 deletions(-) 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); } From 8c6518b2b962a85d4734a7918afac21b8ba96333 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Wed, 5 Nov 2025 18:50:36 +0100 Subject: [PATCH 2/2] fix: keyword-spotting --- .../keyword-spotting/sketch/heart_frames.h | 77 +++---------------- examples/keyword-spotting/sketch/sketch.ino | 33 ++++---- 2 files changed, 25 insertions(+), 85 deletions(-) diff --git a/examples/keyword-spotting/sketch/heart_frames.h b/examples/keyword-spotting/sketch/heart_frames.h index d3ab988..2d25ba7 100644 --- a/examples/keyword-spotting/sketch/heart_frames.h +++ b/examples/keyword-spotting/sketch/heart_frames.h @@ -4,69 +4,16 @@ * 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}, // 1 + {0x3fe31198, 0x0cc06306, 0x0c603600, 0xe0000000, 55}, // 2 + {0x3fe31198, 0x0cc06306, 0x0c603600, 0xe0000000, 55}, // 3 + {0x7ff711f8, 0x0fc07707, 0x1c707701, 0xf0000000, 55}, // 4 + {0xffff11f8, 0x0fc07f07, 0xbc78f783, 0xf8000000, 55}, // 5 + {0xffff11f8, 0x0fc07f07, 0xfc7ff7ef, 0xfe000000, 55}, // 6 + {0xffff11f8, 0x0fc07f07, 0xfc7ff7ff, 0xff000000, 55}, // 7 + {0xffff11f8, 0x0fc07f07, 0xfc7ff7ff, 0xff000000, 55} // 8 }; - -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..e5dcc07 100644 --- a/examples/keyword-spotting/sketch/sketch.ino +++ b/examples/keyword-spotting/sketch/sketch.ino @@ -2,40 +2,33 @@ // // 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(); +Arduino_LED_Matrix matrix; bool awake = false; void setup() { - matrixBegin(); - playAnimation(HeartStatic, 1, 1, 2000); + matrix.begin(); + matrix.clear(); + + matrix.loadFrame(HeartStatic); + Bridge.begin(); - Bridge.provide("keyword_detected", wake_up); + Bridge.provide("keyword_detected", wake_up); } void loop() { if (awake) { - playAnimation(HeartAnim, 8, 1, 50); + matrix.loadSequence(HeartAnim); + matrix.playSequence(); delay(1000); - playAnimation(HeartStatic, 1, 1, 2000); + matrix.loadFrame(HeartStatic); awake = false; } } -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 wake_up() { - awake = true; -} +void wake_up() { awake = true; }