// /0978/NTPClock_ESP32_TM1637/NTPClock_ESP32_TM1637.ino ; update: 2024/01/22 18:00 //Board: ESP32 Dev Module // #include #include // laibrary: TM1637 #include #include #define SSID "ax50anotherZ" // 無線LANアクセスポイントのSSID #define PASS "rock#tang@50Gpgw" // 無線LANアクセスポイントのパスワード // Module connection pins (Digital Pins) #define CLK 18 // SPI SCK #define DIO 19 // SPI MISO TM1637Display display(CLK, DIO); // time struct tm timeInfo; void setup() { Serial.begin(115200); while (!Serial); wifi_connect(); configTime(9 * 3600L, 0, "ntp.nict.jp", "time.google.com", "ntp.jst.mfeed.ad.jp"); delay(1000); Serial.println(" "); Serial.print("29: Connect Internet. IP Address:"); Serial.println(WiFi.localIP()); // 本機のIPアドレスをシリアル表示 long rssi = WiFi.RSSI(); Serial.print("33: signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); getLocalTime(&timeInfo); Serial.println("37: wifi connect "); delay(1000); } void loop() { unsigned int ntime; unsigned long wtime; bool FLG; bool cFLG; wtime = millis(); cFLG = true; display.setBrightness(0x0f); while (1) { getLocalTime(&timeInfo); ntime = timeInfo.tm_hour * 100 + timeInfo.tm_min; if ( cFLG == true ) display.showNumberDecEx(ntime, 0x40, true); if ( cFLG == false ) display.showNumberDecEx(ntime, 0x0, true); FLG = true; if ( cFLG == true ) cFLG = false; else cFLG = true; while (FLG) { if ( millis() - wtime >= 1000 ) { wtime = millis(); FLG = false; } } } } // WiFi接続 void wifi_connect() { int icount; bool FLG; icount = 0; FLG = true; WiFi.mode(WIFI_STA); // 無線LANをSTAモードに設定 WiFi.begin(SSID, PASS); // 無線LANアクセスポイント(SSID)へ接続 Serial.print(SSID); Serial.print(" "); while (WiFi.status() != WL_CONNECTED) { // 接続に成功するまで待つ Serial.print("."); delay(500); // 待ち時間処理 icount++; if ( icount > 20 ) { // 20回トライしても接続できなかった場合タイムアウト(500ms×50)とします ESP.restart(); break; } } }