4848// CONSTANTS
4949// ----------------------------------------------------------------------------------
5050
51- #define EEPROM_SIZE 30 // size of EEPROM to save persistent variables
51+ #define EEPROM_SIZE 32 // size of EEPROM to save persistent variables
5252#define ADR_NM_START_H 0
5353#define ADR_NM_END_H 4
5454#define ADR_NM_START_M 8
6161#define ADR_NM_ACTIVATED 27
6262#define ADR_COLSHIFTSPEED 28
6363#define ADR_COLSHIFTACTIVE 29
64+ #define ADR_HOURANIMATION 30
6465
6566
6667#define NEOPIXELPIN 5 // pin to which the NeoPixels are attached
@@ -160,7 +161,7 @@ const uint32_t colors24bit[NUM_COLORS] = {
160161 LEDMatrix::Color24bit (0 , 0 , 255 ) };
161162
162163uint8_t brightness = 40 ; // current brightness of leds
163- bool sprialDir = false ;
164+ bool animationDir = false ;
164165
165166// timestamp variables
166167long lastheartbeat = millis(); // time of last heartbeat sending
@@ -170,7 +171,8 @@ long lastStateChange = millis(); // time of last state change
170171long lastNTPUpdate = millis() - (PERIOD_NTPUPDATE-3000 ); // time of last NTP update
171172long lastAnimationStep = millis(); // time of last Matrix update
172173long lastNightmodeCheck = millis() - (PERIOD_NIGHTMODECHECK-3000 ); // time of last nightmode check
173- long buttonPressStart = 0 ; // time of push button press start
174+ long buttonPressStart = 0 ; // time of push button press start
175+ long hourAnimationStart = 0 ; // time of hour animation start
174176uint16_t behaviorUpdatePeriod = PERIOD_TIMEVISUUPDATE; // holdes the period in which the behavior should be updated
175177
176178// Create necessary global objects
@@ -194,6 +196,8 @@ bool apmode = false; // stores if WiFi AP mode is activ
194196bool dynColorShiftActive = false ; // stores if dynamic color shift is active
195197uint8_t dynColorShiftPhase = 0 ; // stores the phase of the dynamic color shift
196198uint8_t dynColorShiftSpeed = 1 ; // stores the speed of the dynamic color shift -> used to calc update period
199+ bool hourAnimation = false ; // stores if the hour animation is active
200+ uint32_t hourAnimationDuration = 18000 ; // stores the duration of the hour animation in seconds
197201
198202// nightmode settings
199203uint8_t nightModeStartHour = 22 ;
@@ -360,6 +364,7 @@ void setup() {
360364 loadNightmodeSettingsFromEEPROM ();
361365 loadBrightnessSettingsFromEEPROM ();
362366 loadColorShiftStateFromEEPROM ();
367+ loadHourAnimationSettingsFromEEPROM ();
363368
364369 if (ESP.getResetReason ().equals (" Power On" ) || ESP.getResetReason ().equals (" External System" )){
365370 // test quickly each LED
@@ -424,6 +429,25 @@ void loop() {
424429 delay (1000 );
425430 }
426431 }
432+ if (hourAnimation){
433+ // Show word animation allows from XX:00:00 till XX:00:12 (for 12 seconds every hour)
434+ // start
435+ static uint8_t lastMinutes = 0 ;
436+ uint8_t minutes = ntp.getMinutes ();
437+ if (lastMinutes == 59 && minutes == 0 && currentState == st_clock){
438+ logger.logString (" Start hour animation" );
439+ logger.logString (" Time: " + ntp.getFormattedTime ());
440+ stateChange (st_spiral, false );
441+ hourAnimationStart = millis ();
442+ }
443+ lastMinutes = minutes;
444+
445+ // end
446+ if ((millis () - hourAnimationStart) >= hourAnimationDuration && currentState == st_spiral && hourAnimationStart != 0 ){
447+ stateChange (st_clock, false );
448+ hourAnimationStart = 0 ;
449+ }
450+ }
427451
428452 // handle state behaviours (trigger loopCycles of different states depending on current state)
429453 if (!nightMode && !ledOff && (millis () - lastStep > behaviorUpdatePeriod) && (millis () - lastLEDdirect > TIMEOUT_LEDDIRECT)){
@@ -558,18 +582,18 @@ void updateStateBehavior(uint8_t state){
558582 // state spiral
559583 case st_spiral:
560584 {
561- int res = spiral (false , sprialDir, WIDTH- 6 );
562- if (res && sprialDir == 0 ){
563- // change spiral direction to closing (draw empty leds)
564- sprialDir = 1 ;
565- // init spiral with new spiral direction
566- spiral (true , sprialDir, WIDTH- 6 );
585+ int res = word_animation (false , animationDir );
586+ if (res && animationDir == 0 ){
587+ // change animation direction to closing (draw empty leds)
588+ animationDir = 1 ;
589+ // init animation with new animation direction
590+ word_animation (true , animationDir );
567591
568- }else if (res && sprialDir == 1 ){
569- // reset spiral direction to normal drawing leds
570- sprialDir = 0 ;
571- // init spiral with new spiral direction
572- spiral (true , sprialDir, WIDTH- 6 );
592+ }else if (res && animationDir == 1 ){
593+ // reset animation direction to normal drawing leds
594+ animationDir = 0 ;
595+ // init animation with new animation direction
596+ word_animation (true , animationDir );
573597 }
574598 }
575599 break ;
@@ -657,8 +681,8 @@ void entryAction(uint8_t state){
657681 behaviorUpdatePeriod = PERIOD_ANIMATION;
658682 ledmatrix.setDynamicColorShiftPhase (-1 ); // disable dyn. color shift
659683 // Init spiral with normal drawing mode
660- sprialDir = 0 ;
661- spiral (true , sprialDir, WIDTH- 6 );
684+ animationDir = 0 ;
685+ word_animation (true , animationDir );
662686 break ;
663687 case st_tetris:
664688 ledmatrix.setDynamicColorShiftPhase (-1 ); // disable dyn. color shift
@@ -897,6 +921,17 @@ void loadColorShiftStateFromEEPROM()
897921 logger.logString (" ColorShiftActive: " + String (dynColorShiftActive));
898922}
899923
924+ /* *
925+ * @brief load the hour animation setting from EEPROM
926+ *
927+ */
928+ void loadHourAnimationSettingsFromEEPROM ()
929+ {
930+ hourAnimation = EEPROM.read (ADR_HOURANIMATION);
931+ logger.logString (" HourAnimation: " + String (hourAnimation));
932+ }
933+
934+
900935/* *
901936 * @brief Handler for handling commands sent to "/cmd" url
902937 *
@@ -1080,6 +1115,14 @@ void handleCommand() {
10801115 EEPROM.write (ADR_COLSHIFTACTIVE, dynColorShiftActive);
10811116 EEPROM.commit ();
10821117 }
1118+ else if (server.argName (0 ) == " houranimation" ){
1119+ Serial.println (" HourAnimation change via Webserver" );
1120+ String str = server.arg (0 );
1121+ if (str == " 1" ) hourAnimation = true ;
1122+ else hourAnimation = false ;
1123+ EEPROM.write (ADR_HOURANIMATION, hourAnimation);
1124+ EEPROM.commit ();
1125+ }
10831126 server.send (204 , " text/plain" , " No Content" ); // this page doesn't send back content --> 204
10841127}
10851128
@@ -1142,6 +1185,8 @@ void handleDataRequest() {
11421185 message += " \" colorshift\" :\" " + String (dynColorShiftActive) + " \" " ;
11431186 message += " ," ;
11441187 message += " \" colorshiftspeed\" :\" " + String (dynColorShiftSpeed) + " \" " ;
1188+ message += " ," ;
1189+ message += " \" houranimation\" :\" " + String (hourAnimation) + " \" " ;
11451190 }
11461191 message += " }" ;
11471192 server.send (200 , " application/json" , message);
0 commit comments