// /0978/NTPClock_LOLIN32_TM1637/NTPClock_LOLIN32_TM1637.ino ; update: 2024/01/22 20:40 //Board: ESP32 Dev Module // #include #include "time.h" #include #define CLK 22 //Wire SCL #define DIO 21 //Wire SDA const char* ssid = "ax50anotherZ"; const char* password = "rock#tang@50Gpgw"; const char* ntpServer = "ntp.nict.jp"; const long gmtOffset_sec = 3600*9; // JST const int daylightOffset_sec = 0; static char buf[30];//20 TM1637Display display(CLK, DIO); uint8_t data[]= { 0xff, 0xff, 0xff, 0xff }; // all '1' struct tm timeinfo; static bool cFLG=true; unsigned int ntime; ///byte Hour = 0; ///byte Min = 0; //byte Sec = 0; void printLocalTime(){ if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); return; } // time_t epTime = time(NULL); ///timeClient.getEpochTime(); // timeinfo = *localtime(&epTime); // Serial.println(&timeinfo, "%H:%M:%S"); // sprintf(buf, "32: %02d:%02d", timeinfo.tm_hour, timeinfo.tm_min); // Serial.println(buf); } void setup(){ Serial.begin(115200); while (!Serial); display.setBrightness(0x0f); //connect to WiFi Serial.printf("39: Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED"); //init and get the time configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTime(); //disconnect WiFi as it's no longer needed WiFi.disconnect(true); WiFi.mode(WIFI_OFF); } void loop(){ delay(1000); // time_t epTime = time(NULL); ///timeClient.getEpochTime(); // timeinfo = *localtime(&epTime); getLocalTime(&timeinfo); ntime = timeinfo.tm_hour * 100 + timeinfo.tm_min; /// Hour = timeinfo.tm_hour; /// Min = timeinfo.tm_min; /// Sec = timeinfo.tm_sec; // sprintf(buf, "%02d:%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec); // Serial.println(buf); /// Serial.print(Hour);Serial.print(":");Serial.print(Min);Serial.print(":");Serial.println(Sec); /// data[0] = display.encodeDigit(Hour / 10); /// data[1] = display.encodeDigit(Hour % 10) | 0b10000000; /// data[2] = display.encodeDigit(Min / 10); /// data[3] = display.encodeDigit(Min % 10); /// display.setSegments(data); if ( cFLG == true ) display.showNumberDecEx(ntime, 0x40, true); else if ( cFLG == false ) display.showNumberDecEx(ntime, 0x0, true); cFLG = !cFLG; }