Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 65 additions & 31 deletions wordclock_esp8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,36 @@
// CONSTANTS
// ----------------------------------------------------------------------------------

#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 ADR_STATE 26
#define ADR_NM_ACTIVATED 27
#define ADR_COLSHIFTSPEED 28
#define ADR_COLSHIFTACTIVE 29

#define EEPROM_VERSION_CODE 2 // Change this value when defaults settings change

// EEPROM address map (all uint8_t, 1 byte each)
#define EEPROM_SIZE 13 // size of EEPROM to save persistent variables
#define ADR_EEPROM_VERSION 0 // uint8_t
#define ADR_NM_START_H 1 // uint8_t
#define ADR_NM_END_H 2 // uint8_t
#define ADR_NM_START_M 3 // uint8_t
#define ADR_NM_END_M 4 // uint8_t
#define ADR_BRIGHTNESS 5 // uint8_t
#define ADR_MC_RED 6 // uint8_t
#define ADR_MC_GREEN 7 // uint8_t
#define ADR_MC_BLUE 8 // uint8_t
#define ADR_STATE 9 // uint8_t
#define ADR_NM_ACTIVATED 10 // uint8_t
#define ADR_COLSHIFTSPEED 11 // uint8_t
#define ADR_COLSHIFTACTIVE 12 // uint8_t

// DEFAULT SETTINGS (if one changes this, also increment the EEPROM_VERSION_CODE, to ensure that the EEPROM is updated with the new defaults)
#define DEFAULT_NM_START_HOUR 22 // default start hour of nightmode (0-23)
#define DEFAULT_NM_START_MIN 5 // default start minute of nightmode (0-59)
Copy link

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default start minute is set to 5, but the original initialization on line 216 was 0. This changes the default nightmode start time from 22:00 to 22:05, which may be an unintended behavior change.

Suggested change
#define DEFAULT_NM_START_MIN 5 // default start minute of nightmode (0-59)
#define DEFAULT_NM_START_MIN 0 // default start minute of nightmode (0-59)

Copilot uses AI. Check for mistakes.

#define DEFAULT_NM_END_HOUR 7 // default end hour of nightmode (0-23)
#define DEFAULT_NM_END_MIN 0 // default end minute of nightmode (0-59)
#define DEFAULT_BRIGHTNESS 40 // default brightness of LEDs (0-255)
#define DEFAULT_MC_RED 200 // default main color red value
#define DEFAULT_MC_GREEN 200 // default main color green value
#define DEFAULT_MC_BLUE 0 // default main color blue value
#define DEFAULT_NM_ACTIVATED 1 // if function nightmode is activated (0 = deactivated, 1 = activated)
#define DEFAULT_COLSHIFT_SPEED 1 // needs to be between larger than 0 (1 = slowest, 255 = fastest)
#define DEFAULT_COLSHIFT_ACTIVE 0 // if dynamic color shift is active (0 = deactivated, 1 = activated)

#define NEOPIXELPIN 5 // pin to which the NeoPixels are attached
#define BUTTONPIN 14 // pin to which the button is attached
Expand Down Expand Up @@ -159,7 +175,7 @@ const uint32_t colors24bit[NUM_COLORS] = {
LEDMatrix::Color24bit(0, 128, 0),
LEDMatrix::Color24bit(0, 0, 255) };

uint8_t brightness = 40; // current brightness of leds
uint8_t brightness = DEFAULT_BRIGHTNESS; // current brightness of leds
bool sprialDir = false;

// timestamp variables
Expand All @@ -182,24 +198,24 @@ Tetris mytetris = Tetris(&ledmatrix, &logger);
Snake mysnake = Snake(&ledmatrix, &logger);
Pong mypong = Pong(&ledmatrix, &logger);

float filterFactor = DEFAULT_SMOOTHING_FACTOR;// stores smoothing factor for led transition
uint8_t currentState = st_clock; // stores current state
bool stateAutoChange = false; // stores state of automatic state change
bool nightMode = false; // stores state of nightmode
bool nightModeActivated = true; // stores if the function nightmode is activated (its not the state of nightmode)
bool ledOff = false; // stores state of led off
uint32_t maincolor_clock = colors24bit[2]; // color of the clock and digital clock
uint32_t maincolor_snake = colors24bit[1]; // color of the random snake animation
bool apmode = false; // stores if WiFi AP mode is active
bool dynColorShiftActive = false; // stores if dynamic color shift is active
uint8_t dynColorShiftPhase = 0; // stores the phase of the dynamic color shift
uint8_t dynColorShiftSpeed = 1; // stores the speed of the dynamic color shift -> used to calc update period
float filterFactor = DEFAULT_SMOOTHING_FACTOR; // stores smoothing factor for led transition
uint8_t currentState = st_clock; // stores current state
bool stateAutoChange = false; // stores state of automatic state change
bool nightMode = false; // stores state of nightmode
bool nightModeActivated = DEFAULT_NM_ACTIVATED; // stores if the function nightmode is activated (its not the state of nightmode)
bool ledOff = false; // stores state of led off
uint32_t maincolor_clock = colors24bit[2]; // color of the clock and digital clock
uint32_t maincolor_snake = colors24bit[1]; // color of the random snake animation
bool apmode = false; // stores if WiFi AP mode is active
bool dynColorShiftActive = DEFAULT_COLSHIFT_ACTIVE; // stores if dynamic color shift is active
uint8_t dynColorShiftPhase = 0; // stores the phase of the dynamic color shift
uint8_t dynColorShiftSpeed = DEFAULT_COLSHIFT_SPEED; // stores the speed of the dynamic color shift -> used to calc update period

// nightmode settings
uint8_t nightModeStartHour = 22;
uint8_t nightModeStartMin = 0;
uint8_t nightModeEndHour = 7;
uint8_t nightModeEndMin = 0;
uint8_t nightModeStartHour = DEFAULT_NM_START_HOUR;
uint8_t nightModeStartMin = DEFAULT_NM_START_MIN;
uint8_t nightModeEndHour = DEFAULT_NM_END_HOUR;
uint8_t nightModeEndMin = DEFAULT_NM_END_MIN;

// Watchdog counter to trigger restart if NTP update was not possible 30 times in a row (5min)
int watchdogCounter = 30;
Expand All @@ -221,6 +237,24 @@ void setup() {
//Init EEPROM
EEPROM.begin(EEPROM_SIZE);

// Check EEPROM version code
uint8_t storedVersion = EEPROM.read(ADR_EEPROM_VERSION);
if (storedVersion != EEPROM_VERSION_CODE) {
// Set new defaults
EEPROM.write(ADR_EEPROM_VERSION, EEPROM_VERSION_CODE);
EEPROM.write(ADR_NM_START_H, DEFAULT_NM_START_HOUR);
EEPROM.write(ADR_NM_START_M, DEFAULT_NM_START_MIN);
EEPROM.write(ADR_NM_END_H, DEFAULT_NM_END_HOUR);
EEPROM.write(ADR_NM_END_M, DEFAULT_NM_END_MIN);
EEPROM.write(ADR_BRIGHTNESS, DEFAULT_BRIGHTNESS);
setMainColor(DEFAULT_MC_RED, DEFAULT_MC_GREEN, DEFAULT_MC_BLUE);
Copy link

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setMainColor function writes to EEPROM addresses ADR_MC_RED, ADR_MC_GREEN, and ADR_MC_BLUE, but these addresses have changed from the original 20, 22, 24 to new values 6, 7, 8. However, the function is being called during EEPROM initialization before these new address values are written individually on lines 249, which creates redundant writes to the same locations.

Suggested change
setMainColor(DEFAULT_MC_RED, DEFAULT_MC_GREEN, DEFAULT_MC_BLUE);

Copilot uses AI. Check for mistakes.

EEPROM.write(ADR_STATE, st_clock);
EEPROM.write(ADR_NM_ACTIVATED, DEFAULT_NM_ACTIVATED);
EEPROM.write(ADR_COLSHIFTSPEED, DEFAULT_COLSHIFT_SPEED);
EEPROM.write(ADR_COLSHIFTACTIVE, DEFAULT_COLSHIFT_ACTIVE);
EEPROM.commit();
}

// configure button pin as input
pinMode(BUTTONPIN, INPUT_PULLUP);

Expand Down