#include #include #include #include #include #include #include #include #include //https://github.com/tzapu/WiFiManager #include // https://github.com/JChristensen/Timezone #include // https://github.com/PaulStoffregen/Time #include // https://github.com/PaulStoffregen/DS1307RTC #include // https://github.com/arduino-libraries/NTPClient #include // https://github.com/avishorp/TM1637 // Central European Time (Frankfurt, Paris) TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time Timezone CE(CEST, CET); // NTP WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 3600000); // timelib time_t utc; time_t local; // display //TM1637Display display(1, 3); TM1637Display display(D6, D5); // pinClk, pinDIO uint8_t data[] = { 0xff, 0xff, 0xff, 0xff }; uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 }; char buf[5]; char prev[5] = { '0','0','0','0' }; void setup() { WiFiManager wifiManager; wifiManager.setTimeout(180); if(!wifiManager.autoConnect("clock")) { ESP.reset(); delay(5000); } ArduinoOTA.begin(); ESP.wdtEnable(WDTO_8S); // put your setup code here, to run once: //Wire.begin(0,2); // 00-sda,02-sdl Wire.begin(D2,D1); timeClient.begin(); setSyncProvider(RTC.get); // link to hardware clock display.clear(); display.setBrightness(0x0a); display.setSegments(data); } void loop() { ESP.wdtFeed(); ArduinoOTA.handle(); yield(); delay(100); // put your main code here, to run repeatedly: if(timeClient.update()) { RTC.set(timeClient.getEpochTime()); } yield(); utc = now(); local = CE.toLocal(utc); yield(); sprintf(buf, "%.2d%.2d",hour(local), minute(local)); if(second(local) % 2 == 0) { display.showNumberDecEx(hour(local), 0b10000000, true, 2, 0); } else { display.showNumberDecEx(hour(local), 0b11100000, true, 2, 0); } if(strcmp(buf, prev) != 0) { display.showNumberDecEx(hour(local), 0b11100000, true, 2, 0); display.showNumberDecEx(minute(local), 0b11100000, true, 2, 2); strcpy(prev , buf); } yield(); }