// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define NTP_SERVER "time.inrim.it"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 0
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
tft.setCursor(15, 1);
tft.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
tft.setCursor(0, 1);
tft.println("Connection Err");
return;
}
tft.setCursor(8, 0);
tft.println(&timeinfo, "%H:%M:%S");
tft.setCursor(0, 1);
tft.println(&timeinfo, "%d/%m/%Y %Z");
}
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.setCursor(0, 0);
tft.print("Connecting to WiFi ");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
tft.fillScreen(ILI9341_BLACK);
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.println("Online");
tft.setCursor(0, 1);
tft.println("Updating time...");
tft.fillScreen(ILI9341_BLACK);
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
tft.fillScreen(ILI9341_BLACK);
printLocalTime();
delay(1000);
}