//#include <ESP8266WiFi.h> // Utilizada no circuito físico no ESP8266
#include <WiFi.h> // Para simular no WOKWI utilizada no ESP32
#include <Wire.h> // Nativa do Arduino não precisa instalar
#include <LiquidCrystal_I2C.h> // Biclioteca para o LCD
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(39, 16, 2);
//-----------------------SERVIDOR NTP ---------------------
#define NTP_SERVER "pool.ntp.org" // para sincronizar relógios
//----------------------- WIFI ----------------------------
const char* ssid = "Wokwi-GUEST";
const char* password = "";
//const char* ssid = "TP-Link_9A10";
//const char* password = "59166146";
// Função para imprimir a hora local
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 0); // posicione para o local que deseja iniciar a escrita no LCD
LCD.print("Falha ao obter a hora");
return;
}
char dateBuffer[20];
strftime(dateBuffer, sizeof(dateBuffer), "%d/%m/%Y", &timeinfo);
LCD.setCursor(0, 0);
LCD.print(dateBuffer);
char timeBuffer[20];
strftime(timeBuffer, sizeof(timeBuffer), "%H:%M:%S", &timeinfo);
LCD.setCursor(0, 1);
LCD.print(timeBuffer);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // monitor serial com taxa 115200
pinMode(4, INPUT); // definir o pino que vc vai usar como saída para o botão
WiFi.begin(ssid, password); // iniciar o wifi no esp8266
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.println("Unsuccessful Wi-Fi connection"); // wifi não pode ser conectado
}
LCD.init(); // iniciar o lcd
LCD.backlight(); // ligar o led de fundo
LCD.setCursor(0, 0);// definir a posição do cursor/escrita
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
configTime(-3 * 3600, 0, NTP_SERVER); // Ajuste para Brasília
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
Serial.println(digitalRead(4)); // Printando
printLocalTime(); // Chama a função para imprimir a hora
delay(250);
////////// criar um condicional para mostrar a data quando o botão for apertado
}