Skip to content

Commit 7ebaf6c

Browse files
Merge branch 'main' into hour_animation
2 parents 6473a83 + 722d02d commit 7ebaf6c

7 files changed

Lines changed: 136 additions & 54 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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
}
244244

245245
.show{
246-
height: 280px;
246+
height: 320px;
247247
transition: height 1s;
248248
}
249249

@@ -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">
@@ -559,6 +563,7 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
559563
document.getElementById("nm_start").value = myVar.nightModeStart.replace("-", ":");
560564
document.getElementById("nm_end").value = myVar.nightModeEnd.replace("-", ":");
561565
document.getElementById("brightness").value = parseInt(myVar.brightness);
566+
document.getElementById("nm_brightness").value = parseInt(myVar.nightModeBrightness);
562567
document.getElementById("colorshiftspeed").value = parseInt(myVar.colorshiftspeed);
563568

564569
updateDisplay(parseInt(myVar.modeid));
@@ -635,6 +640,7 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
635640
var nmStart = document.getElementById("nm_start");
636641
var nmEnd = document.getElementById("nm_end");
637642
var sld_brightness = document.getElementById("brightness");
643+
var sld_nm_brightness = document.getElementById("nm_brightness");
638644
var sld_colorshiftspeed = document.getElementById("colorshiftspeed");
639645
var ckb_resetWifi = document.querySelector('input[id="ResetWifi"]');
640646
var cmdstr = "./cmd?setting=";
@@ -645,6 +651,8 @@ <h1 id="headline">WORDCLOCK 2.0</h1>
645651
cmdstr += sld_brightness.value;
646652
cmdstr += "-";
647653
cmdstr += sld_colorshiftspeed.value;
654+
cmdstr += "-";
655+
cmdstr += sld_nm_brightness.value;
648656
console.log(cmdstr);
649657
sendCommand(cmdstr);
650658
if(ckb_resetWifi.checked) {

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: 98 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,39 @@
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 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-
#define ADR_HOURANIMATION 30
65-
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 15 // 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+
71+
// DEFAULT SETTINGS (if one changes this, also increment the EEPROM_VERSION_CODE, to ensure that the EEPROM is updated with the new defaults)
72+
#define DEFAULT_NM_START_HOUR 22 // default start hour of nightmode (0-23)
73+
#define DEFAULT_NM_START_MIN 5 // default start minute of nightmode (0-59)
74+
#define DEFAULT_NM_END_HOUR 7 // default end hour of nightmode (0-23)
75+
#define DEFAULT_NM_END_MIN 0 // default end minute of nightmode (0-59)
76+
#define DEFAULT_BRIGHTNESS 40 // default brightness of LEDs (10-255)
77+
#define DEFAULT_MC_RED 200 // default main color red value
78+
#define DEFAULT_MC_GREEN 200 // default main color green value
79+
#define DEFAULT_MC_BLUE 0 // default main color blue value
80+
#define DEFAULT_NM_ACTIVATED 1 // if function nightmode is activated (0 = deactivated, 1 = activated)
81+
#define DEFAULT_NM_BRIGHTNESS 0 // default brightness during night mode (0-255)
82+
#define DEFAULT_COLSHIFT_SPEED 1 // needs to be between larger than 0 (1 = slowest, 255 = fastest)
83+
#define DEFAULT_COLSHIFT_ACTIVE 0 // if dynamic color shift is active (0 = deactivated, 1 = activated)
6684

6785
#define NEOPIXELPIN 5 // pin to which the NeoPixels are attached
6886
#define BUTTONPIN 14 // pin to which the button is attached
@@ -160,7 +178,7 @@ const uint32_t colors24bit[NUM_COLORS] = {
160178
LEDMatrix::Color24bit(0, 128, 0),
161179
LEDMatrix::Color24bit(0, 0, 255) };
162180

163-
uint8_t brightness = 40; // current brightness of leds
181+
uint8_t brightness = DEFAULT_BRIGHTNESS; // current brightness of leds
164182
bool animationDir = false;
165183

166184
// timestamp variables
@@ -184,26 +202,27 @@ Tetris mytetris = Tetris(&ledmatrix, &logger);
184202
Snake mysnake = Snake(&ledmatrix, &logger);
185203
Pong mypong = Pong(&ledmatrix, &logger);
186204

187-
float filterFactor = DEFAULT_SMOOTHING_FACTOR;// stores smoothing factor for led transition
188-
uint8_t currentState = st_clock; // stores current state
189-
bool stateAutoChange = false; // stores state of automatic state change
190-
bool nightMode = false; // stores state of nightmode
191-
bool nightModeActivated = true; // stores if the function nightmode is activated (its not the state of nightmode)
192-
bool ledOff = false; // stores state of led off
193-
uint32_t maincolor_clock = colors24bit[2]; // color of the clock and digital clock
194-
uint32_t maincolor_snake = colors24bit[1]; // color of the random snake animation
195-
bool apmode = false; // stores if WiFi AP mode is active
196-
bool dynColorShiftActive = false; // stores if dynamic color shift is active
197-
uint8_t dynColorShiftPhase = 0; // stores the phase of the dynamic color shift
198-
uint8_t dynColorShiftSpeed = 1; // stores the speed of the dynamic color shift -> used to calc update period
205+
float filterFactor = DEFAULT_SMOOTHING_FACTOR; // stores smoothing factor for led transition
206+
uint8_t currentState = st_clock; // stores current state
207+
bool stateAutoChange = false; // stores state of automatic state change
208+
bool nightMode = false; // stores state of nightmode
209+
bool nightModeActivated = DEFAULT_NM_ACTIVATED; // stores if the function nightmode is activated (its not the state of nightmode)
210+
bool ledOff = false; // stores state of led off
211+
uint32_t maincolor_clock = colors24bit[2]; // color of the clock and digital clock
212+
uint32_t maincolor_snake = colors24bit[1]; // color of the random snake animation
213+
bool apmode = false; // stores if WiFi AP mode is active
214+
bool dynColorShiftActive = DEFAULT_COLSHIFT_ACTIVE; // stores if dynamic color shift is active
215+
uint8_t dynColorShiftPhase = 0; // stores the phase of the dynamic color shift
216+
uint8_t dynColorShiftSpeed = DEFAULT_COLSHIFT_SPEED; // stores the speed of the dynamic color shift -> used to calc update period
199217
bool hourAnimation = false; // stores if the hour animation is active
200218
uint32_t hourAnimationDuration = 18000; // stores the duration of the hour animation in seconds
201219

202220
// nightmode settings
203-
uint8_t nightModeStartHour = 22;
204-
uint8_t nightModeStartMin = 0;
205-
uint8_t nightModeEndHour = 7;
206-
uint8_t nightModeEndMin = 0;
221+
uint8_t nightModeStartHour = DEFAULT_NM_START_HOUR;
222+
uint8_t nightModeStartMin = DEFAULT_NM_START_MIN;
223+
uint8_t nightModeEndHour = DEFAULT_NM_END_HOUR;
224+
uint8_t nightModeEndMin = DEFAULT_NM_END_MIN;
225+
uint8_t nightModeBrightness = DEFAULT_NM_BRIGHTNESS;
207226

208227
// Watchdog counter to trigger restart if NTP update was not possible 30 times in a row (5min)
209228
int watchdogCounter = 30;
@@ -225,6 +244,25 @@ void setup() {
225244
//Init EEPROM
226245
EEPROM.begin(EEPROM_SIZE);
227246

247+
// Check EEPROM version code
248+
uint8_t storedVersion = EEPROM.read(ADR_EEPROM_VERSION);
249+
if (storedVersion != EEPROM_VERSION_CODE) {
250+
// Set new defaults
251+
EEPROM.write(ADR_EEPROM_VERSION, EEPROM_VERSION_CODE);
252+
EEPROM.write(ADR_NM_START_H, DEFAULT_NM_START_HOUR);
253+
EEPROM.write(ADR_NM_START_M, DEFAULT_NM_START_MIN);
254+
EEPROM.write(ADR_NM_END_H, DEFAULT_NM_END_HOUR);
255+
EEPROM.write(ADR_NM_END_M, DEFAULT_NM_END_MIN);
256+
EEPROM.write(ADR_BRIGHTNESS, DEFAULT_BRIGHTNESS);
257+
setMainColor(DEFAULT_MC_RED, DEFAULT_MC_GREEN, DEFAULT_MC_BLUE);
258+
EEPROM.write(ADR_STATE, st_clock);
259+
EEPROM.write(ADR_NM_ACTIVATED, DEFAULT_NM_ACTIVATED);
260+
EEPROM.write(ADR_COLSHIFTSPEED, DEFAULT_COLSHIFT_SPEED);
261+
EEPROM.write(ADR_COLSHIFTACTIVE, DEFAULT_COLSHIFT_ACTIVE);
262+
EEPROM.write(ADR_NM_BRIGHTNESS, DEFAULT_NM_BRIGHTNESS);
263+
EEPROM.commit();
264+
}
265+
228266
// configure button pin as input
229267
pinMode(BUTTONPIN, INPUT_PULLUP);
230268

@@ -364,6 +402,7 @@ void setup() {
364402
loadNightmodeSettingsFromEEPROM();
365403
loadBrightnessSettingsFromEEPROM();
366404
loadColorShiftStateFromEEPROM();
405+
loadNightmodeBrightnessFromEEPROM();
367406
loadHourAnimationSettingsFromEEPROM();
368407

369408
if(ESP.getResetReason().equals("Power On") || ESP.getResetReason().equals("External System")){
@@ -450,15 +489,23 @@ void loop() {
450489
}
451490

452491
// handle state behaviours (trigger loopCycles of different states depending on current state)
453-
if(!nightMode && !ledOff && (millis() - lastStep > behaviorUpdatePeriod) && (millis() - lastLEDdirect > TIMEOUT_LEDDIRECT)){
492+
if(!ledOff && (millis() - lastStep > behaviorUpdatePeriod) && (millis() - lastLEDdirect > TIMEOUT_LEDDIRECT)){
454493
updateStateBehavior(currentState);
455494
lastStep = millis();
456495
}
457496

458-
// Turn off LEDs if ledOff is true or nightmode is active
459-
if((ledOff || nightMode) && !waitForTimeAfterReboot){
497+
// Turn off LEDs if ledOff is true
498+
if(ledOff && !waitForTimeAfterReboot){
460499
ledmatrix.gridFlush();
461500
}
501+
502+
// Apply night mode brightness
503+
if(nightMode && !ledOff && !waitForTimeAfterReboot){
504+
ledmatrix.setBrightness(nightModeBrightness);
505+
}
506+
else if(!nightMode && !ledOff && !waitForTimeAfterReboot){
507+
ledmatrix.setBrightness(brightness);
508+
}
462509

463510
// periodically write colors to matrix
464511
if(millis() - lastAnimationStep > PERIOD_MATRIXUPDATE && !waitForTimeAfterReboot && (millis() - lastLEDdirect > TIMEOUT_LEDDIRECT)){
@@ -470,7 +517,7 @@ void loop() {
470517
handleButton();
471518

472519
// handle state changes
473-
if(stateAutoChange && (millis() - lastStateChange > PERIOD_STATECHANGE) && !nightMode && !ledOff){
520+
if(stateAutoChange && (millis() - lastStateChange > PERIOD_STATECHANGE) && !ledOff){
474521
// increment state variable and trigger state change
475522
stateChange((currentState + 1) % NUM_STATES, false);
476523

@@ -921,6 +968,16 @@ void loadColorShiftStateFromEEPROM()
921968
logger.logString("ColorShiftActive: " + String(dynColorShiftActive));
922969
}
923970

971+
/**
972+
* @brief Load the night mode brightness from EEPROM
973+
*
974+
*/
975+
void loadNightmodeBrightnessFromEEPROM()
976+
{
977+
nightModeBrightness = EEPROM.read(ADR_NM_BRIGHTNESS);
978+
logger.logString("Night mode brightness: " + String(nightModeBrightness));
979+
}
980+
924981
/**
925982
* @brief load the hour animation setting from EEPROM
926983
*
@@ -1004,6 +1061,7 @@ void handleCommand() {
10041061
nightModeEndMin = split(timestr, '-', 3).toInt();
10051062
brightness = split(timestr, '-', 4).toInt();
10061063
dynColorShiftSpeed = split(timestr, '-', 5).toInt();
1064+
nightModeBrightness = split(timestr, '-', 6).toInt();
10071065
if(nightModeStartHour < 0 || nightModeStartHour > 23) nightModeStartHour = 22;
10081066
if(nightModeStartMin < 0 || nightModeStartMin > 59) nightModeStartMin = 0;
10091067
if(nightModeEndHour < 0 || nightModeEndHour > 23) nightModeEndHour = 7;
@@ -1016,11 +1074,13 @@ void handleCommand() {
10161074
EEPROM.write(ADR_NM_END_M, nightModeEndMin);
10171075
EEPROM.write(ADR_BRIGHTNESS, brightness);
10181076
EEPROM.write(ADR_COLSHIFTSPEED, dynColorShiftSpeed);
1077+
EEPROM.write(ADR_NM_BRIGHTNESS, nightModeBrightness);
10191078
EEPROM.commit();
10201079
logger.logString("Nightmode starts at: " + String(nightModeStartHour) + ":" + String(nightModeStartMin));
10211080
logger.logString("Nightmode ends at: " + String(nightModeEndHour) + ":" + String(nightModeEndMin));
10221081
logger.logString("Brightness: " + String(brightness));
10231082
logger.logString("ColorShiftSpeed: " + String(dynColorShiftSpeed));
1083+
logger.logString("Night mode brightness: " + String(nightModeBrightness));
10241084
ledmatrix.setBrightness(brightness);
10251085
lastNightmodeCheck = millis() - PERIOD_NIGHTMODECHECK;
10261086
}
@@ -1182,6 +1242,8 @@ void handleDataRequest() {
11821242
message += ",";
11831243
message += "\"brightness\":\"" + String(brightness) + "\"";
11841244
message += ",";
1245+
message += "\"nightModeBrightness\":\"" + String(nightModeBrightness) + "\"";
1246+
message += ",";
11851247
message += "\"colorshift\":\"" + String(dynColorShiftActive) + "\"";
11861248
message += ",";
11871249
message += "\"colorshiftspeed\":\"" + String(dynColorShiftSpeed) + "\"";

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
}

wordclockfunctions.ino_swiss

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const String clockStringSwiss = "ESPESCHAFUFVIERTUBFZAAZWANZGSIVORABOHWORTUHRHA
99
*/
1010
void drawMinuteIndicator(uint8_t minutes, uint32_t color){
1111
//separate LEDs for minutes in an additional row
12-
{
1312
switch (minutes%5)
1413
{
1514
case 0:
@@ -31,7 +30,6 @@ void drawMinuteIndicator(uint8_t minutes, uint32_t color){
3130
ledmatrix.setMinIndicator(0b1111, color);
3231
break;
3332
}
34-
}
3533
}
3634

3735
/**
@@ -93,20 +91,10 @@ int showStringOnClock(String message, uint32_t color){
9391
* @param minutes minutes of the time value
9492
* @return String time as sentence
9593
*/
96-
String timeToString(uint8_t hours, uint8_t minutes, bool puristModeActive){
94+
String timeToString(uint8_t hours, uint8_t minutes){
9795

9896
//ES IST
99-
String message = "";
100-
101-
if(puristModeActive){
102-
message = "";
103-
if(minutes < 5 || (minutes >=30 && minutes < 35)){
104-
message = "ES ESCH ";
105-
}
106-
}
107-
else{
108-
message = "ES ESCH ";
109-
}
97+
String message = "ES ESCH ";
11098

11199
//show minutes
112100
if(minutes >= 5 && minutes < 10)

0 commit comments

Comments
 (0)