From dec0455743916cd5b29ba2116820dde84dad29ec Mon Sep 17 00:00:00 2001 From: Techniccontroller Date: Sun, 9 Apr 2023 13:34:54 +0200 Subject: [PATCH 1/2] init the grids with {0} instead of fixed size --- ledmatrix.h | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/ledmatrix.h b/ledmatrix.h index 05a491c..e30fa75 100644 --- a/ledmatrix.h +++ b/ledmatrix.h @@ -40,30 +40,10 @@ class LEDMatrix{ uint16_t currentLimit; // target representation of matrix as 2D array - uint32_t targetgrid[HEIGHT][WIDTH] = {{0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}}; + uint32_t targetgrid[HEIGHT][WIDTH] = {0}; // current representation of matrix as 2D array - uint32_t currentgrid[HEIGHT][WIDTH] = {{0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0}}; + uint32_t currentgrid[HEIGHT][WIDTH] = {0}; // target representation of minutes indicator leds uint32_t targetindicators[4] = {0, 0, 0, 0}; From 359f3b8f5433fc6520e06abbf60566ea36804cef Mon Sep 17 00:00:00 2001 From: Techniccontroller Date: Tue, 11 Apr 2023 09:03:01 +0200 Subject: [PATCH 2/2] add color persistence --- wordclock_esp8266.ino | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/wordclock_esp8266.ino b/wordclock_esp8266.ino index c696780..57183c8 100644 --- a/wordclock_esp8266.ino +++ b/wordclock_esp8266.ino @@ -48,12 +48,15 @@ // CONSTANTS // ---------------------------------------------------------------------------------- -#define EEPROM_SIZE 20 // size of EEPROM to save persistent variables +#define EEPROM_SIZE 30 // size of EEPROM to save persistent variables #define ADR_NM_START_H 0 #define ADR_NM_END_H 4 #define ADR_NM_START_M 8 #define ADR_NM_END_M 12 #define ADR_BRIGHTNESS 16 +#define ADR_MC_RED 20 +#define ADR_MC_GREEN 22 +#define ADR_MC_BLUE 24 #define NEOPIXELPIN 5 // pin to which the NeoPixels are attached @@ -212,6 +215,9 @@ void setup() { //Init EEPROM EEPROM.begin(EEPROM_SIZE); + // Load color for clock from EEPROM + loadMainColor(); + // configure button pin as input pinMode(BUTTONPIN, INPUT_PULLUP); @@ -718,6 +724,35 @@ void handleButton(){ lastButtonState = buttonPressed; } +/** + * @brief Set main color + * + */ + +void setMainColor(uint8_t red, uint8_t green, uint8_t blue){ + maincolor_clock = LEDMatrix::Color24bit(red, green, blue); + EEPROM.put(ADR_MC_RED, red); + EEPROM.put(ADR_MC_GREEN, green); + EEPROM.put(ADR_MC_BLUE, blue); + EEPROM.commit(); +} + +/** + * @brief Load maincolor from EEPROM + * +*/ + +void loadMainColor(){ + uint8_t red = EEPROM.read(ADR_MC_RED); + uint8_t green = EEPROM.read(ADR_MC_GREEN); + uint8_t blue = EEPROM.read(ADR_MC_BLUE); + if(int(red) + int(green) + int(blue) < 50){ + maincolor_clock = colors24bit[2]; + }else{ + maincolor_clock = LEDMatrix::Color24bit(red, green, blue); + } +} + /** * @brief Handler for handling commands sent to "/cmd" url * @@ -741,7 +776,7 @@ void handleCommand() { logger.logString("g: " + String(greenstr.toInt())); logger.logString("b: " + String(bluestr.toInt())); // set new main color - maincolor_clock = LEDMatrix::Color24bit(redstr.toInt(), greenstr.toInt(), bluestr.toInt()); + setMainColor(redstr.toInt(), greenstr.toInt(), bluestr.toInt()); } else if (server.argName(0) == "mode") // the parameter which was sent to this server is mode change {