diff --git a/network-server.h b/network-server.h deleted file mode 100644 index 22f75e1..0000000 --- a/network-server.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -/* - * Define these to fetch from a wallart-server - * - * https://git.woozle.org/neale/wallart-server - */ -#define ART_HOSTNAME "www.woozle.org" -#define ART_PORT 443 -#define ART_PATH "/wallart/wallart.bin" diff --git a/times.h b/times.h new file mode 100644 index 0000000..44a6af2 --- /dev/null +++ b/times.h @@ -0,0 +1,6 @@ +#pragma once + +#define MILLISECOND 1 +#define SECOND (1000 * MILLISECOND) +#define MINUTE (60 * SECOND) +#define HOUR (60 * MINUTE) diff --git a/wallart.ino b/wallart.ino index 6a492a8..c56c4b5 100644 --- a/wallart.ino +++ b/wallart.ino @@ -1,24 +1,44 @@ #include #include #include +#include +#include +#include "times.h" #include "picker.h" #include "network.h" -#include "network-server.h" #define NEOPIXEL_PIN 32 #define GRIDLEN 64 #define WFM_PASSWORD "artsy fartsy" +#define TIME_OFFSET (-7 * HOUR / SECOND) -#define MILLISECOND 1 -#define SECOND (1000 * MILLISECOND) +/* + * The hours when the day begins and ends. + * During the day, everything is brighter. + */ +#define DAY_BEGIN 7 +#define DAY_END 21 +#define DAY_BRIGHTNESS 0x80 +#define NIGHT_BRIGHTNESS 0x10 + +/* + * Define these to fetch from a wallart-server + * + * https://git.woozle.org/neale/wallart-server + */ +#define ART_HOSTNAME "www.woozle.org" +#define ART_PORT 443 +#define ART_PATH "/wallart/wallart.bin" #define HTTPS_TIMEOUT (2 * SECOND) CRGB grid[GRIDLEN]; +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP, TIME_OFFSET); + void setup() { FastLED.addLeds(grid, GRIDLEN); - FastLED.setBrightness(64); // Maybe it's the plexiglass but for my build I really need to dial back the red FastLED.setCorrection(0xc0ffff); network_setup(WFM_PASSWORD); @@ -222,19 +242,72 @@ void spinner(int count=32) { } } +void displayTime(unsigned long duration = 20 * SECOND) { + if (!connected()) return; + unsigned long end = millis() + duration; + FastLED.clear(); + + while (millis() < end) { + timeClient.update(); + int hh = timeClient.getHours(); + int mm = timeClient.getMinutes(); + int ss = timeClient.getSeconds(); + uint8_t hue = HUE_YELLOW; + + if (hh >= 12) { + hue = HUE_ORANGE; + hh -= 12; + } + + for (int i = 0; i < 12; i++) { + // Omit first and last position on a row + int pos = i + 1; + if (pos > 6) { + pos += 2; + } + + grid[pos + 0] = CHSV(hue, 255, (i= DAY_BEGIN) && (hh < DAY_END)) { + FastLED.setBrightness(DAY_BRIGHTNESS); + } else { + FastLED.setBrightness(NIGHT_BRIGHTNESS); + } +} + void loop() { Picker p; uint8_t getprob = 4; + bool conn = connected(); + bool day = true; - if ((NetArtFrames == 0) || !connected()) { + timeClient.update(); + if (timeClient.isTimeSet()) { + int hh = timeClient.getHours(); + day = ((hh > DAY_BEGIN) && (hh < DAY_END)); + } + FastLED.setBrightness(day?DAY_BRIGHTNESS:NIGHT_BRIGHTNESS); + + if ((NetArtFrames == 0) || !conn) { getprob = 16; } - - if (p.Pick(getprob)) { - netget(); - } else if (p.Pick(4)) { + + if (p.Pick(getprob)) { + netget(); + } else if (day && p.Pick(4)) { + // These can be hella bright netart(); - } else if (p.Pick(1)) { + } else if (p.Pick(1)) { fade(); singleCursor(20); } else if (p.Pick(1)) { @@ -251,5 +324,7 @@ void loop() { cm5(8); } else if (p.Pick(2)) { cm5(16); - } + } else if (p.Pick(4)) { + displayTime(1 * MINUTE); + } }