#include #include "SSD1306.h" #include const char* ssid = "XXXXXXXXXXXXX"; const char* password = "XXXXXXXXX"; //NTP関連 //struct tm timeInfo; char date[20],hour_minute[20]; SSD1306 display(0x3c, 4, 5); void setup() { Serial.begin(115200); display.init();//SSD1306を初期化 WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi.."); } Serial.println("Connected to the WiFi network"); configTime(-9 * 3600L, 0, "ntp.nict.jp", "time.google.com", "ntp.jst.mfeed.ad.jp");//NTPの設定 } void show_time(){ time_t t; struct tm *tm; static const char *wd[7] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat"}; t = time(NULL); tm = localtime(&t); // getLocalTime(&timeInfo);//tmオブジェクトのtimeInfoに現在時刻を入れ込む sprintf(date, "%04d/%02d/%02d (%s)",tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, wd[tm->tm_wday]);//日付に変換 sprintf(hour_minute, "%02d:%02d",tm->tm_hour, tm->tm_min);//時間に変換 Serial.println(date); Serial.println(hour_minute); display.clear(); //日付を上の方に表示 display.setFont(ArialMT_Plain_16); display.drawString(0, 0, date); //時間を中央に大きく表示 display.setFont(ArialMT_Plain_24); display.drawString(20, 20, hour_minute); display.display(); } void loop() { if ((WiFi.status() == WL_CONNECTED)) { show_time(); delay(15000); } }