Created
April 29, 2026 14:34
-
-
Save je4npw/9b274a07440dc4cf72a8fe66a568e637 to your computer and use it in GitHub Desktop.
Relatório de aula prática - Sistemas Embarcados - 7º semestre - Ciência da Computação - Aluno Jean Patrick Wilhvock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiFi.h> | |
| #include <LiquidCrystal_I2C.h> | |
| #include "time.h" | |
| // Configurações do Wi-Fi do Wokwi | |
| const char* ssid = "Wokwi-GUEST"; | |
| const char* password = ""; | |
| // Configurações do Servidor NTP | |
| const char* ntpServer = "pool.ntp.org"; | |
| const long gmtOffset_sec = -10800; // Ajuste para o fuso horário de Brasília (-3h) | |
| const int daylightOffset_sec = 0; | |
| // Inicialização do Display LCD (Endereço 0x27, 16 colunas, 2 linhas) | |
| LiquidCrystal_I2C lcd(0x27, 16, 2); | |
| void setup() { | |
| Serial.begin(115200); | |
| // Inicializa LCD | |
| lcd.init(); | |
| lcd.backlight(); | |
| lcd.setCursor(0, 0); | |
| lcd.print("Conectando..."); | |
| // Conecta ao Wi-Fi | |
| WiFi.begin(ssid, password); | |
| while (WiFi.status() != WL_CONNECTED) { | |
| delay(500); | |
| Serial.print("."); | |
| } | |
| // Configura o tempo via NTP | |
| configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); | |
| } | |
| void loop() { | |
| struct tm timeinfo; | |
| if (!getLocalTime(&timeinfo)) { | |
| lcd.setCursor(0, 0); | |
| lcd.print("Erro no NTP "); | |
| return; | |
| } | |
| // Formatação da Hora e Status Online (Linha 1) | |
| char horaFormatada[16]; | |
| // %H:%M:%S - Hora:Minuto:Segundo | "ON" para indicação de online | |
| strftime(horaFormatada, 16, "%H:%M:%S ON", &timeinfo); | |
| // Formatação da Data (Linha 2) | |
| char dataFormatada[16]; | |
| // %d/%m/%Y - Dia/Mês/Ano | |
| strftime(dataFormatada, 16, "%d/%m/%Y", &timeinfo); | |
| // Atualização do Display | |
| lcd.setCursor(0, 0); | |
| lcd.print(horaFormatada); | |
| lcd.setCursor(0, 1); | |
| lcd.print(dataFormatada); | |
| // Lógica de atualização a cada 250 ms conforme solicitado | |
| delay(250); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment