#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const char* ssid = "Wokwi-GUEST";
const char* password = "";

const long utcOffsetInSeconds = -21600; /* UTC-6h you need to calculate the time zone, example: UTC 5h =60*60*5=18000)*/
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  timeClient.begin();
  timeClient.setTimeOffset(utcOffsetInSeconds);

  Serial.println("Ready!");
}

void loop() {
  timeClient.update();
  display.clearDisplay();
  display.setCursor(37, 0);
  display.setTextSize(2);
  display.println("Hora:");
  display.setCursor(10, 20);
  display.setTextSize(2);
  display.print(timeClient.getFormattedTime());
  display.display();
  delay(1000);
}
Loading
ssd1306