From da1899c6a302a5ce279084c5c72523cc8b81d366 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 29 Nov 2020 11:38:56 -0700 Subject: [PATCH] Fix overflow on day calculation --- holiday-lights.ino | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/holiday-lights.ino b/holiday-lights.ino index d99c932..b374ec3 100644 --- a/holiday-lights.ino +++ b/holiday-lights.ino @@ -32,13 +32,20 @@ // Color for all-white mode #define WHITE 0x886655 +// Some units of time +#define MILLISECOND 1L +#define SECOND (1000 * MILLISECOND) +#define MINUTE (60 * SECOND) +#define HOUR (60 * MINUTE) +#define DAY (24 * HOUR) + // The Neopixel library masks interrupts while writing. // This means you lose time. // How much time do you lose? // I'm guessing 10 minutes a day. -#define SNOSSLOSS (10 * 60 * 1000) -#define DAY (24 * 60 * 60 * 1000 - SNOSSLOSS) -#define ON_FOR (5 * 60 * 60 * 1000) + +#define SNOSSLOSS_DAY (DAY - (10 * MINUTE)) +#define ON_FOR (5 * HOUR) const char *messages[] = { "happy holiday ARK", @@ -154,7 +161,7 @@ void loop() { white = !white; } - if (forever || white || (millis() % DAY < ON_FOR)) { + if (FOREVER || white || (millis() % SNOSSLOSS_DAY < ON_FOR)) { update |= strandUpdate(white); update |= morseUpdate(); } else {