Skip to content

Commit 4faf200

Browse files
Merge branch 'main' into hour_animation_frame_light
2 parents 607efe9 + 722d02d commit 4faf200

6 files changed

Lines changed: 136 additions & 42 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ We've got some interesting branches in this repo inspired by user feedback. Thes
9292
![compile esp8266 workflow](https://github.com/techniccontroller/wordclock_esp8266/actions/workflows/compile_esp8266.yml/badge.svg?branch=rgbw_leds)
9393
- [**static_background_pattern**](https://github.com/techniccontroller/wordclock_esp8266/tree/static_background_pattern): This branch allows to light up specific letters always during clock mode. E.G., to display some special words in another color.
9494
![compile esp8266 workflow](https://github.com/techniccontroller/wordclock_esp8266/actions/workflows/compile_esp8266.yml/badge.svg?branch=static_background_pattern)
95+
- [**frame_light**](https://github.com/techniccontroller/wordclock_esp8266/tree/frame_light): This branch allows to add an additional LEDs around the clock, as background/frame light it has the same color as the clock. Thanks to Sandro for the idea.
96+
![compile esp8266 workflow](https://github.com/techniccontroller/wordclock_esp8266/actions/workflows/compile_esp8266.yml/badge.svg?branch=frame_light)
9597

9698
## Install needed Libraries
9799

data/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
280280
<label for="colorshiftspeed">Color shift speed:</label>
281281
<input type="range" id="colorshiftspeed" name="volume" min="0" max="50">
282282
</div>
283+
<div class="number-container">
284+
<label for="nm_brightness">Nightmode brightness:</label>
285+
<input type="range" id="nm_brightness" name="volume" min="0" max="100">
286+
</div>
283287
<div class="number-container">
284288
<label for="nm_start" style="align-self: flex-start">Nightmode start time: </label>
285289
<input type="time" id="nm_start" name="nm_start" min="00:00" max="23:59">
@@ -586,6 +590,7 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
586590
document.getElementById("nm_start").value = myVar.nightModeStart.replace("-", ":");
587591
document.getElementById("nm_end").value = myVar.nightModeEnd.replace("-", ":");
588592
document.getElementById("brightness").value = parseInt(myVar.brightness);
593+
document.getElementById("nm_brightness").value = parseInt(myVar.nightModeBrightness);
589594
document.getElementById("brightnessFrame").value = parseInt(myVar.brightnessFrame);
590595
document.getElementById("colorshiftspeed").value = parseInt(myVar.colorshiftspeed);
591596

@@ -663,6 +668,7 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
663668
var nmStart = document.getElementById("nm_start");
664669
var nmEnd = document.getElementById("nm_end");
665670
var sld_brightness = document.getElementById("brightness");
671+
var sld_nm_brightness = document.getElementById("nm_brightness");
666672
var sld_brightnessFrame = document.getElementById("brightnessFrame");
667673
var sld_colorshiftspeed = document.getElementById("colorshiftspeed");
668674
var ckb_resetWifi = document.querySelector('input[id="ResetWifi"]');
@@ -675,6 +681,8 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
675681
cmdstr += "-";
676682
cmdstr += sld_colorshiftspeed.value;
677683
cmdstr += "-";
684+
cmdstr += sld_nm_brightness.value;
685+
cmdstr += "-";
678686
cmdstr += sld_brightnessFrame.value;
679687
console.log(cmdstr);
680688
sendCommand(cmdstr);

ntp_client_plus.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,26 @@ unsigned int NTPClientPlus::getDayOfWeek()
314314
return this->_dayOfWeek;
315315
}
316316

317+
/**
318+
* @brief Getter for day of the month
319+
*
320+
* @return unsigned int
321+
*/
322+
unsigned int NTPClientPlus::getDayOfMonth()
323+
{
324+
return this->_dateDay;
325+
}
326+
327+
/**
328+
* @brief Getter for the month number
329+
*
330+
* @return unsigned int
331+
*/
332+
unsigned int NTPClientPlus::getMonthNumber()
333+
{
334+
return this->_dateMonth;
335+
}
336+
317337
/**
318338
* @brief Function to calc current year
319339
*

ntp_client_plus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class NTPClientPlus{
3333
String getFormattedDate();
3434
void calcDate();
3535
unsigned int getDayOfWeek();
36+
unsigned int getDayOfMonth();
37+
unsigned int getMonthNumber();
3638
unsigned int getYear();
3739
bool isLeapYear(unsigned int year);
3840
int getMonth(int dayOfYear);

wordclock_esp8266.ino

Lines changed: 101 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,41 @@
4848
// CONSTANTS
4949
// ----------------------------------------------------------------------------------
5050

51-
#define EEPROM_SIZE 32 // size of EEPROM to save persistent variables
52-
#define ADR_NM_START_H 0
53-
#define ADR_NM_END_H 1
54-
#define ADR_NM_START_M 2
55-
#define ADR_NM_END_M 3
56-
#define ADR_BRIGHTNESS 4
57-
#define ADR_MC_RED 5
58-
#define ADR_MC_GREEN 6
59-
#define ADR_MC_BLUE 7
60-
#define ADR_BRIGHTNESS_FRAME 10
61-
#define ADR_FRAMELIGHTACTIVE 11
62-
#define ADR_STATE 26
63-
#define ADR_NM_ACTIVATED 27
64-
#define ADR_COLSHIFTSPEED 28
65-
#define ADR_COLSHIFTACTIVE 29
66-
#define ADR_HOURANIMATION 30
67-
51+
#define EEPROM_VERSION_CODE 3 // Change this value when defaults settings change
52+
53+
// EEPROM address map (all uint8_t, 1 byte each)
54+
#define EEPROM_SIZE 14 // 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+
#define ADR_NM_BRIGHTNESS 13 // uint8_t
69+
#define ADR_HOURANIMATION 14 // uint8_t
70+
#define ADR_BRIGHTNESS_FRAME 15 // uint8_t
71+
#define ADR_FRAMELIGHTACTIVE 16 // uint8_t
72+
73+
// DEFAULT SETTINGS (if one changes this, also increment the EEPROM_VERSION_CODE, to ensure that the EEPROM is updated with the new defaults)
74+
#define DEFAULT_NM_START_HOUR 22 // default start hour of nightmode (0-23)
75+
#define DEFAULT_NM_START_MIN 5 // default start minute of nightmode (0-59)
76+
#define DEFAULT_NM_END_HOUR 7 // default end hour of nightmode (0-23)
77+
#define DEFAULT_NM_END_MIN 0 // default end minute of nightmode (0-59)
78+
#define DEFAULT_BRIGHTNESS 40 // default brightness of LEDs (10-255)
79+
#define DEFAULT_MC_RED 200 // default main color red value
80+
#define DEFAULT_MC_GREEN 200 // default main color green value
81+
#define DEFAULT_MC_BLUE 0 // default main color blue value
82+
#define DEFAULT_NM_ACTIVATED 1 // if function nightmode is activated (0 = deactivated, 1 = activated)
83+
#define DEFAULT_NM_BRIGHTNESS 0 // default brightness during night mode (0-255)
84+
#define DEFAULT_COLSHIFT_SPEED 1 // needs to be between larger than 0 (1 = slowest, 255 = fastest)
85+
#define DEFAULT_COLSHIFT_ACTIVE 0 // if dynamic color shift is active (0 = deactivated, 1 = activated)
6886

6987
#define NEOPIXELPIN 5 // pin to which the NeoPixels are attached
7088
#define NEOPIXELPIN_FRAME 4 // pin to which the NeoPixels for the frame light are attached
@@ -166,7 +184,7 @@ const uint32_t colors24bit[NUM_COLORS] = {
166184
LEDMatrix::Color24bit(0, 128, 0),
167185
LEDMatrix::Color24bit(0, 0, 255) };
168186

169-
uint8_t brightness = 40; // current brightness of leds
187+
uint8_t brightness = DEFAULT_BRIGHTNESS; // current brightness of leds
170188
uint8_t brightnessFrame = 40; // brightness of leds for frame light
171189
bool animationDir = false;
172190

@@ -191,27 +209,28 @@ Tetris mytetris = Tetris(&ledmatrix, &logger);
191209
Snake mysnake = Snake(&ledmatrix, &logger);
192210
Pong mypong = Pong(&ledmatrix, &logger);
193211

194-
float filterFactor = DEFAULT_SMOOTHING_FACTOR;// stores smoothing factor for led transition
195-
uint8_t currentState = st_clock; // stores current state
196-
bool stateAutoChange = false; // stores state of automatic state change
197-
bool nightMode = false; // stores state of nightmode
198-
bool nightModeActivated = true; // stores if the function nightmode is activated (its not the state of nightmode)
199-
bool ledOff = false; // stores state of led off
200-
uint32_t maincolor_clock = colors24bit[2]; // color of the clock and digital clock
201-
uint32_t maincolor_snake = colors24bit[1]; // color of the random snake animation
202-
bool apmode = false; // stores if WiFi AP mode is active
203-
bool dynColorShiftActive = false; // stores if dynamic color shift is active
204-
uint8_t dynColorShiftPhase = 0; // stores the phase of the dynamic color shift
205-
uint8_t dynColorShiftSpeed = 1; // stores the speed of the dynamic color shift -> used to calc update period
212+
float filterFactor = DEFAULT_SMOOTHING_FACTOR; // stores smoothing factor for led transition
213+
uint8_t currentState = st_clock; // stores current state
214+
bool stateAutoChange = false; // stores state of automatic state change
215+
bool nightMode = false; // stores state of nightmode
216+
bool nightModeActivated = DEFAULT_NM_ACTIVATED; // stores if the function nightmode is activated (its not the state of nightmode)
217+
bool ledOff = false; // stores state of led off
218+
uint32_t maincolor_clock = colors24bit[2]; // color of the clock and digital clock
219+
uint32_t maincolor_snake = colors24bit[1]; // color of the random snake animation
220+
bool apmode = false; // stores if WiFi AP mode is active
221+
bool dynColorShiftActive = DEFAULT_COLSHIFT_ACTIVE; // stores if dynamic color shift is active
222+
uint8_t dynColorShiftPhase = 0; // stores the phase of the dynamic color shift
223+
uint8_t dynColorShiftSpeed = DEFAULT_COLSHIFT_SPEED; // stores the speed of the dynamic color shift -> used to calc update period
206224
bool hourAnimation = false; // stores if the hour animation is active
207225
uint32_t hourAnimationDuration = 18000; // stores the duration of the hour animation in seconds
208226
bool frameLightActive = false; // stores if frame light is active
209227

210228
// nightmode settings
211-
uint8_t nightModeStartHour = 22;
212-
uint8_t nightModeStartMin = 0;
213-
uint8_t nightModeEndHour = 7;
214-
uint8_t nightModeEndMin = 0;
229+
uint8_t nightModeStartHour = DEFAULT_NM_START_HOUR;
230+
uint8_t nightModeStartMin = DEFAULT_NM_START_MIN;
231+
uint8_t nightModeEndHour = DEFAULT_NM_END_HOUR;
232+
uint8_t nightModeEndMin = DEFAULT_NM_END_MIN;
233+
uint8_t nightModeBrightness = DEFAULT_NM_BRIGHTNESS;
215234

216235
// Watchdog counter to trigger restart if NTP update was not possible 30 times in a row (5min)
217236
int watchdogCounter = 30;
@@ -233,6 +252,25 @@ void setup() {
233252
//Init EEPROM
234253
EEPROM.begin(EEPROM_SIZE);
235254

255+
// Check EEPROM version code
256+
uint8_t storedVersion = EEPROM.read(ADR_EEPROM_VERSION);
257+
if (storedVersion != EEPROM_VERSION_CODE) {
258+
// Set new defaults
259+
EEPROM.write(ADR_EEPROM_VERSION, EEPROM_VERSION_CODE);
260+
EEPROM.write(ADR_NM_START_H, DEFAULT_NM_START_HOUR);
261+
EEPROM.write(ADR_NM_START_M, DEFAULT_NM_START_MIN);
262+
EEPROM.write(ADR_NM_END_H, DEFAULT_NM_END_HOUR);
263+
EEPROM.write(ADR_NM_END_M, DEFAULT_NM_END_MIN);
264+
EEPROM.write(ADR_BRIGHTNESS, DEFAULT_BRIGHTNESS);
265+
setMainColor(DEFAULT_MC_RED, DEFAULT_MC_GREEN, DEFAULT_MC_BLUE);
266+
EEPROM.write(ADR_STATE, st_clock);
267+
EEPROM.write(ADR_NM_ACTIVATED, DEFAULT_NM_ACTIVATED);
268+
EEPROM.write(ADR_COLSHIFTSPEED, DEFAULT_COLSHIFT_SPEED);
269+
EEPROM.write(ADR_COLSHIFTACTIVE, DEFAULT_COLSHIFT_ACTIVE);
270+
EEPROM.write(ADR_NM_BRIGHTNESS, DEFAULT_NM_BRIGHTNESS);
271+
EEPROM.commit();
272+
}
273+
236274
// configure button pin as input
237275
pinMode(BUTTONPIN, INPUT_PULLUP);
238276

@@ -375,6 +413,7 @@ void setup() {
375413
loadNightmodeSettingsFromEEPROM();
376414
loadBrightnessSettingsFromEEPROM();
377415
loadColorShiftStateFromEEPROM();
416+
loadNightmodeBrightnessFromEEPROM();
378417
loadHourAnimationSettingsFromEEPROM();
379418

380419
if(ESP.getResetReason().equals("Power On") || ESP.getResetReason().equals("External System")){
@@ -461,15 +500,23 @@ void loop() {
461500
}
462501

463502
// handle state behaviours (trigger loopCycles of different states depending on current state)
464-
if(!nightMode && !ledOff && (millis() - lastStep > behaviorUpdatePeriod) && (millis() - lastLEDdirect > TIMEOUT_LEDDIRECT)){
503+
if(!ledOff && (millis() - lastStep > behaviorUpdatePeriod) && (millis() - lastLEDdirect > TIMEOUT_LEDDIRECT)){
465504
updateStateBehavior(currentState);
466505
lastStep = millis();
467506
}
468507

469-
// Turn off LEDs if ledOff is true or nightmode is active
470-
if((ledOff || nightMode) && !waitForTimeAfterReboot){
508+
// Turn off LEDs if ledOff is true
509+
if(ledOff && !waitForTimeAfterReboot){
471510
ledmatrix.gridFlush();
472511
}
512+
513+
// Apply night mode brightness
514+
if(nightMode && !ledOff && !waitForTimeAfterReboot){
515+
ledmatrix.setBrightness(nightModeBrightness);
516+
}
517+
else if(!nightMode && !ledOff && !waitForTimeAfterReboot){
518+
ledmatrix.setBrightness(brightness);
519+
}
473520

474521
// periodically write colors to matrix
475522
if(millis() - lastAnimationStep > PERIOD_MATRIXUPDATE && !waitForTimeAfterReboot && (millis() - lastLEDdirect > TIMEOUT_LEDDIRECT)){
@@ -483,7 +530,7 @@ void loop() {
483530
handleButton();
484531

485532
// handle state changes
486-
if(stateAutoChange && (millis() - lastStateChange > PERIOD_STATECHANGE) && !nightMode && !ledOff){
533+
if(stateAutoChange && (millis() - lastStateChange > PERIOD_STATECHANGE) && !ledOff){
487534
// increment state variable and trigger state change
488535
stateChange((currentState + 1) % NUM_STATES, false);
489536

@@ -940,6 +987,16 @@ void loadColorShiftStateFromEEPROM()
940987
logger.logString("ColorShiftActive: " + String(dynColorShiftActive));
941988
}
942989

990+
/**
991+
* @brief Load the night mode brightness from EEPROM
992+
*
993+
*/
994+
void loadNightmodeBrightnessFromEEPROM()
995+
{
996+
nightModeBrightness = EEPROM.read(ADR_NM_BRIGHTNESS);
997+
logger.logString("Night mode brightness: " + String(nightModeBrightness));
998+
}
999+
9431000
/**
9441001
* @brief load the hour animation setting from EEPROM
9451002
*
@@ -1023,7 +1080,8 @@ void handleCommand() {
10231080
nightModeEndMin = split(timestr, '-', 3).toInt();
10241081
brightness = split(timestr, '-', 4).toInt();
10251082
dynColorShiftSpeed = split(timestr, '-', 5).toInt();
1026-
brightnessFrame = split(timestr, '-', 6).toInt();
1083+
nightModeBrightness = split(timestr, '-', 6).toInt();
1084+
brightnessFrame = split(timestr, '-', 7).toInt();
10271085
if(nightModeStartHour < 0 || nightModeStartHour > 23) nightModeStartHour = 22;
10281086
if(nightModeStartMin < 0 || nightModeStartMin > 59) nightModeStartMin = 0;
10291087
if(nightModeEndHour < 0 || nightModeEndHour > 23) nightModeEndHour = 7;
@@ -1038,12 +1096,14 @@ void handleCommand() {
10381096
EEPROM.write(ADR_BRIGHTNESS, brightness);
10391097
EEPROM.write(ADR_BRIGHTNESS_FRAME, brightnessFrame);
10401098
EEPROM.write(ADR_COLSHIFTSPEED, dynColorShiftSpeed);
1099+
EEPROM.write(ADR_NM_BRIGHTNESS, nightModeBrightness);
10411100
EEPROM.commit();
10421101
logger.logString("Nightmode starts at: " + String(nightModeStartHour) + ":" + String(nightModeStartMin));
10431102
logger.logString("Nightmode ends at: " + String(nightModeEndHour) + ":" + String(nightModeEndMin));
10441103
logger.logString("Brightness: " + String(brightness));
10451104
logger.logString("Brightness Frame: " + String(brightnessFrame));
10461105
logger.logString("ColorShiftSpeed: " + String(dynColorShiftSpeed));
1106+
logger.logString("Night mode brightness: " + String(nightModeBrightness));
10471107
ledmatrix.setBrightness(brightness);
10481108
backgroundLEDStrip.setBrightness(brightnessFrame);
10491109
lastNightmodeCheck = millis() - PERIOD_NIGHTMODECHECK;
@@ -1214,6 +1274,8 @@ void handleDataRequest() {
12141274
message += ",";
12151275
message += "\"brightness\":\"" + String(brightness) + "\"";
12161276
message += ",";
1277+
message += "\"nightModeBrightness\":\"" + String(nightModeBrightness) + "\"";
1278+
message += ",";
12171279
message += "\"brightnessFrame\":\"" + String(brightnessFrame) + "\"";
12181280
message += ",";
12191281
message += "\"colorshift\":\"" + String(dynColorShiftActive) + "\"";

wordclockfunctions.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ String timeToString(uint8_t hours,uint8_t minutes){
114114
}
115115
else if(minutes >= 20 && minutes < 25)
116116
{
117-
message += "ZEHN VOR HALB ";
117+
message += "ZWANZIG NACH ";
118118
}
119119
else if(minutes >= 25 && minutes < 30)
120120
{
@@ -130,7 +130,7 @@ String timeToString(uint8_t hours,uint8_t minutes){
130130
}
131131
else if(minutes >= 40 && minutes < 45)
132132
{
133-
message += "ZEHN NACH HALB ";
133+
message += "ZWANZIG VOR ";
134134
}
135135
else if(minutes >= 45 && minutes < 50)
136136
{
@@ -150,7 +150,7 @@ String timeToString(uint8_t hours,uint8_t minutes){
150150
{
151151
hours -= 12;
152152
}
153-
if(minutes >= 20)
153+
if(minutes >= 25)
154154
{
155155
hours++;
156156
}

0 commit comments

Comments
 (0)