4848// CONSTANTS
4949// ----------------------------------------------------------------------------------
5050
51- #define EEPROM_SIZE 30 // size of EEPROM to save persistent variables
52- #define ADR_NM_START_H 0
53- #define ADR_NM_END_H 4
54- #define ADR_NM_START_M 8
55- #define ADR_NM_END_M 12
56- #define ADR_BRIGHTNESS 16
57- #define ADR_MC_RED 20
58- #define ADR_MC_GREEN 22
59- #define ADR_MC_BLUE 24
60- #define ADR_STATE 26
61- #define ADR_NM_ACTIVATED 27
62- #define ADR_COLSHIFTSPEED 28
63- #define ADR_COLSHIFTACTIVE 29
64-
51+ #define EEPROM_VERSION_CODE 2 // Change this value when defaults settings change
52+
53+ // EEPROM address map (all uint8_t, 1 byte each)
54+ #define EEPROM_SIZE 13 // size of EEPROM to save persistent variables
55+ #define ADR_EEPROM_VERSION 0 // uint8_t
56+ #define ADR_NM_START_H 1 // uint8_t
57+ #define ADR_NM_END_H 2 // uint8_t
58+ #define ADR_NM_START_M 3 // uint8_t
59+ #define ADR_NM_END_M 4 // uint8_t
60+ #define ADR_BRIGHTNESS 5 // uint8_t
61+ #define ADR_MC_RED 6 // uint8_t
62+ #define ADR_MC_GREEN 7 // uint8_t
63+ #define ADR_MC_BLUE 8 // uint8_t
64+ #define ADR_STATE 9 // uint8_t
65+ #define ADR_NM_ACTIVATED 10 // uint8_t
66+ #define ADR_COLSHIFTSPEED 11 // uint8_t
67+ #define ADR_COLSHIFTACTIVE 12 // uint8_t
68+
69+ // DEFAULT SETTINGS (if one changes this, also increment the EEPROM_VERSION_CODE, to ensure that the EEPROM is updated with the new defaults)
70+ #define DEFAULT_NM_START_HOUR 22 // default start hour of nightmode (0-23)
71+ #define DEFAULT_NM_START_MIN 5 // default start minute of nightmode (0-59)
72+ #define DEFAULT_NM_END_HOUR 7 // default end hour of nightmode (0-23)
73+ #define DEFAULT_NM_END_MIN 0 // default end minute of nightmode (0-59)
74+ #define DEFAULT_BRIGHTNESS 40 // default brightness of LEDs (0-255)
75+ #define DEFAULT_MC_RED 200 // default main color red value
76+ #define DEFAULT_MC_GREEN 200 // default main color green value
77+ #define DEFAULT_MC_BLUE 0 // default main color blue value
78+ #define DEFAULT_NM_ACTIVATED 1 // if function nightmode is activated (0 = deactivated, 1 = activated)
79+ #define DEFAULT_COLSHIFT_SPEED 1 // needs to be between larger than 0 (1 = slowest, 255 = fastest)
80+ #define DEFAULT_COLSHIFT_ACTIVE 0 // if dynamic color shift is active (0 = deactivated, 1 = activated)
6581
6682#define NEOPIXELPIN 5 // pin to which the NeoPixels are attached
6783#define BUTTONPIN 14 // pin to which the button is attached
@@ -159,7 +175,7 @@ const uint32_t colors24bit[NUM_COLORS] = {
159175 LEDMatrix::Color24bit (0 , 128 , 0 ),
160176 LEDMatrix::Color24bit (0 , 0 , 255 ) };
161177
162- uint8_t brightness = 40 ; // current brightness of leds
178+ uint8_t brightness = DEFAULT_BRIGHTNESS ; // current brightness of leds
163179bool sprialDir = false ;
164180
165181// timestamp variables
@@ -182,24 +198,24 @@ Tetris mytetris = Tetris(&ledmatrix, &logger);
182198Snake mysnake = Snake(&ledmatrix, &logger);
183199Pong mypong = Pong(&ledmatrix, &logger);
184200
185- float filterFactor = DEFAULT_SMOOTHING_FACTOR;// stores smoothing factor for led transition
186- uint8_t currentState = st_clock; // stores current state
187- bool stateAutoChange = false ; // stores state of automatic state change
188- bool nightMode = false ; // stores state of nightmode
189- bool nightModeActivated = true ; // stores if the function nightmode is activated (its not the state of nightmode)
190- bool ledOff = false ; // stores state of led off
191- uint32_t maincolor_clock = colors24bit[2 ]; // color of the clock and digital clock
192- uint32_t maincolor_snake = colors24bit[1 ]; // color of the random snake animation
193- bool apmode = false ; // stores if WiFi AP mode is active
194- bool dynColorShiftActive = false ; // stores if dynamic color shift is active
195- uint8_t dynColorShiftPhase = 0 ; // stores the phase of the dynamic color shift
196- uint8_t dynColorShiftSpeed = 1 ; // stores the speed of the dynamic color shift -> used to calc update period
201+ float filterFactor = DEFAULT_SMOOTHING_FACTOR; // stores smoothing factor for led transition
202+ uint8_t currentState = st_clock; // stores current state
203+ bool stateAutoChange = false ; // stores state of automatic state change
204+ bool nightMode = false ; // stores state of nightmode
205+ bool nightModeActivated = DEFAULT_NM_ACTIVATED; // stores if the function nightmode is activated (its not the state of nightmode)
206+ bool ledOff = false ; // stores state of led off
207+ uint32_t maincolor_clock = colors24bit[2 ]; // color of the clock and digital clock
208+ uint32_t maincolor_snake = colors24bit[1 ]; // color of the random snake animation
209+ bool apmode = false ; // stores if WiFi AP mode is active
210+ bool dynColorShiftActive = DEFAULT_COLSHIFT_ACTIVE; // stores if dynamic color shift is active
211+ uint8_t dynColorShiftPhase = 0 ; // stores the phase of the dynamic color shift
212+ uint8_t dynColorShiftSpeed = DEFAULT_COLSHIFT_SPEED; // stores the speed of the dynamic color shift -> used to calc update period
197213
198214// nightmode settings
199- uint8_t nightModeStartHour = 22 ;
200- uint8_t nightModeStartMin = 0 ;
201- uint8_t nightModeEndHour = 7 ;
202- uint8_t nightModeEndMin = 0 ;
215+ uint8_t nightModeStartHour = DEFAULT_NM_START_HOUR ;
216+ uint8_t nightModeStartMin = DEFAULT_NM_START_MIN ;
217+ uint8_t nightModeEndHour = DEFAULT_NM_END_HOUR ;
218+ uint8_t nightModeEndMin = DEFAULT_NM_END_MIN ;
203219
204220// Watchdog counter to trigger restart if NTP update was not possible 30 times in a row (5min)
205221int watchdogCounter = 30 ;
@@ -221,6 +237,24 @@ void setup() {
221237 // Init EEPROM
222238 EEPROM.begin (EEPROM_SIZE);
223239
240+ // Check EEPROM version code
241+ uint8_t storedVersion = EEPROM.read (ADR_EEPROM_VERSION);
242+ if (storedVersion != EEPROM_VERSION_CODE) {
243+ // Set new defaults
244+ EEPROM.write (ADR_EEPROM_VERSION, EEPROM_VERSION_CODE);
245+ EEPROM.write (ADR_NM_START_H, DEFAULT_NM_START_HOUR);
246+ EEPROM.write (ADR_NM_START_M, DEFAULT_NM_START_MIN);
247+ EEPROM.write (ADR_NM_END_H, DEFAULT_NM_END_HOUR);
248+ EEPROM.write (ADR_NM_END_M, DEFAULT_NM_END_MIN);
249+ EEPROM.write (ADR_BRIGHTNESS, DEFAULT_BRIGHTNESS);
250+ setMainColor (DEFAULT_MC_RED, DEFAULT_MC_GREEN, DEFAULT_MC_BLUE);
251+ EEPROM.write (ADR_STATE, st_clock);
252+ EEPROM.write (ADR_NM_ACTIVATED, DEFAULT_NM_ACTIVATED);
253+ EEPROM.write (ADR_COLSHIFTSPEED, DEFAULT_COLSHIFT_SPEED);
254+ EEPROM.write (ADR_COLSHIFTACTIVE, DEFAULT_COLSHIFT_ACTIVE);
255+ EEPROM.commit ();
256+ }
257+
224258 // configure button pin as input
225259 pinMode (BUTTONPIN, INPUT_PULLUP);
226260
0 commit comments