65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
|
|
#include <ESP8266WiFi.h>
|
|
#include <WiFiUdp.h>
|
|
#include <NTP.h>
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
Adafruit_NeoPixel pixels(60, 5, NEO_GRB + NEO_KHZ800);
|
|
|
|
uint16_t ADC_MAX = 900;
|
|
uint16_t ADC_MIN = 250;
|
|
uint8_t ADC_INVERT = 1;
|
|
uint8_t BRIGHT_MIN = 50;
|
|
uint8_t BRIGHT_MAX = 255;
|
|
|
|
const char *ssid = put your ssid here;
|
|
const char *password = put your psk here;
|
|
|
|
WiFiUDP wifiUdp;
|
|
NTP ntp(wifiUdp);
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
WiFi.begin(ssid, password);
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
Serial.println("Connecting ...");
|
|
delay(500);
|
|
}
|
|
Serial.println("Connected");
|
|
ntp.ruleDST("CEST", Last, Sun, Mar, 2, 120); // last sunday in march 2:00, timetone +120min (+1 GMT + 1h summertime offset)
|
|
ntp.ruleSTD("CET", Last, Sun, Oct, 3, 60); // last sunday in october 3:00, timezone +60min (+1 GMT)
|
|
ntp.begin();
|
|
Serial.println("start NTP");
|
|
pixels.begin();
|
|
}
|
|
|
|
uint8_t sixtyToPixel(int8_t sixty) {
|
|
return (60 - ((sixty+30) % 60)) % 60;
|
|
}
|
|
|
|
void loop() {
|
|
delay(1000);
|
|
uint16_t brightness = analogRead(A0);
|
|
uint8_t bscale = (uint8_t) (255*(min(max(brightness, ADC_MIN), ADC_MAX) - ADC_MIN) / (ADC_MAX - ADC_MIN));
|
|
if (ADC_INVERT) {
|
|
bscale = 255 - bscale;
|
|
}
|
|
bscale = min(max(bscale, BRIGHT_MIN), BRIGHT_MAX);
|
|
Serial.print(brightness);
|
|
Serial.print(" -> ");
|
|
Serial.println(bscale);
|
|
ntp.update();
|
|
Serial.println(ntp.formattedTime("%T"));
|
|
uint8_t h = sixtyToPixel((ntp.hours() % 12) * 5 + (ntp.minutes() / 12));
|
|
uint8_t hl = sixtyToPixel((ntp.hours() % 12) * 5 + (ntp.minutes() / 12) - 1);
|
|
uint8_t hr = sixtyToPixel((ntp.hours() % 12) * 5 + (ntp.minutes() / 12) + 1);
|
|
uint8_t m = sixtyToPixel(ntp.minutes());
|
|
uint8_t s = sixtyToPixel(ntp.seconds());
|
|
pixels.clear();
|
|
pixels.setPixelColor(hl, pixels.getPixelColor(hl) | (bscale << 16));
|
|
pixels.setPixelColor(h, pixels.getPixelColor(h) | (bscale << 16));
|
|
pixels.setPixelColor(hr, pixels.getPixelColor(hr) | (bscale << 16));
|
|
pixels.setPixelColor(m, pixels.getPixelColor(m) | (bscale << 8) | (bscale >> 2));
|
|
pixels.setPixelColor(s, pixels.getPixelColor(s) | bscale);
|
|
pixels.show();
|
|
}
|