diff options
author | Torben Egmose <torben.egmose@gmail.com> | 2021-02-07 21:23:32 +0100 |
---|---|---|
committer | Torben Egmose <torben.egmose@gmail.com> | 2021-02-07 21:23:32 +0100 |
commit | 68d56b547fea6ea70dc2e485a70d51f0419e3042 (patch) | |
tree | 1ba80271057567d5bbdcb4807ea185c4ab2d3884 | |
parent | 3d7b03a257c97b0c4147c733d21b038ab9123371 (diff) |
first release
-rw-r--r-- | src/main.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/main.cpp b/src/main.cpp index 3683a20..e20c0ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,20 @@ #include <Arduino.h> #include <Wire.h> +#include <ESP8266WiFi.h> +#include <ESP8266WiFiMulti.h> +#include <WiFiUdp.h> +#include <ArduinoOTA.h> + +#include <DNSServer.h> +#include <ESP8266WebServer.h> +#include <WiFiManager.h>//https://github.com/tzapu/WiFiManager + #include <Timezone.h> // https://github.com/JChristensen/Timezone #include <TimeLib.h> // https://github.com/PaulStoffregen/Time #include <DS1307RTC.h> // https://github.com/PaulStoffregen/DS1307RTC #include <NTPClient.h> // https://github.com/arduino-libraries/NTPClient #include <TM1637Display.h> // https://github.com/avishorp/TM1637 -#include <WiFiManager.h>//https://github.com/tzapu/WiFiManager - -#include <ESP8266WiFi.h> -#include <ESP8266WiFiMulti.h> -#include <WiFiUdp.h> -#include <ArduinoOTA.h> // Central European Time (Frankfurt, Paris) TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time @@ -20,7 +23,7 @@ Timezone CE(CEST, CET); // NTP WiFiUDP ntpUDP; -NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 600000); +NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 3600000); // timelib time_t utc; @@ -28,22 +31,21 @@ time_t local; // display //TM1637Display display(1, 3); -TM1637Display display(D8, D7); // pinClk, pinDIO +TM1637Display display(D6, D5); // pinClk, pinDIO uint8_t data[] = { 0xff, 0xff, 0xff, 0xff }; uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 }; -char buf[4]; -char prev[4]; +char buf[5]; +char prev[5] = { '0','0','0','0' }; void setup() { - WiFi.mode(WIFI_STA); - WiFiManager wifiManager; - wifiManager.setTimeout(600); + wifiManager.setTimeout(180); if(!wifiManager.autoConnect("clock")) { ESP.reset(); + delay(5000); } ArduinoOTA.begin(); @@ -53,8 +55,10 @@ void setup() { //Wire.begin(0,2); // 00-sda,02-sdl Wire.begin(D2,D1); timeClient.begin(); - setSyncProvider(RTC.get); + setSyncProvider(RTC.get); // link to hardware clock display.clear(); + display.setBrightness(0x0a); + display.setSegments(data); } void loop() { @@ -62,6 +66,7 @@ void loop() { ArduinoOTA.handle(); yield(); + delay(100); // put your main code here, to run repeatedly: if(timeClient.update()) { @@ -76,13 +81,16 @@ void loop() { yield(); sprintf(buf, "%.2d%.2d",hour(local), minute(local)); - data[0] = display.encodeDigit(buf[0] - '0'); - data[1] = display.encodeDigit(buf[1] - '0'); - data[2] = display.encodeDigit(buf[2] - '0'); - data[3] = display.encodeDigit(buf[3] - '0'); + + 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.setSegments(data); + display.showNumberDecEx(hour(local), 0b11100000, true, 2, 0); + display.showNumberDecEx(minute(local), 0b11100000, true, 2, 2); strcpy(prev , buf); } |