// https://www.youtube.com/watch?v=ZWRT4mDb8O0
// Acrescimo OTA by Ezequiel M. Rezende
#include <TM1637Display.h> // https://github.com/avishorp/TM1637
#include <NTPClient.h> // https://github.com/arduino-libraries/NTPClient
#include <WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
// Module connection pins (Digital Pins)
// For ESP-01:
// CLK to GPIO2
// DIO to GPIO0
#define CLK 22
#define DIO 5
// Set up the TM1637 Display
TM1637Display display(CLK, DIO);
//Dados para conexão com a rede Wi-fi
const char* ssid = "Wokwi-GUEST";
const char* password = "";
/*
You need to adjust the UTC offset for your timezone in milliseconds. Refer the list of UTC time offsets. Here are some examples for different timezones:
For UTC -5.00 : -5 * 60 * 60 : -18000
For UTC +1.00 : 1 * 60 * 60 : 3600
For UTC +0.00 : 0 * 60 * 60 : 0
const long utcOffsetInSeconds = 3600;
*/
const long utcOffsetInSeconds = 18000;
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
void setup(){
Serial.begin(115200);
Serial.println("Iniciando...");
display.clear(); // Clear the display:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
// ----------------------------------------------------------------------------------------------- //
// Porta padrao do ESP8266 para OTA eh 8266 - Voce pode mudar ser quiser, mas deixe indicado!
// ArduinoOTA.setPort(8266);
// O Hostname padrao eh esp8266-[ChipID], mas voce pode mudar com essa funcao
ArduinoOTA.setHostname("IotClock_7x4_Ota");
// Nenhuma senha eh pedida, mas voce pode dar mais seguranca pedindo uma senha pra gravar
// ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.onStart([]() {
Serial.println("Inicio...");
});
ArduinoOTA.onEnd([]() {
Serial.println("nFim!");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progresso: %u%%r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Erro [%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Autenticacao Falhou");
else if (error == OTA_BEGIN_ERROR) Serial.println("Falha no Inicio");
else if (error == OTA_CONNECT_ERROR) Serial.println("Falha na Conexao");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Falha na Recepcao");
else if (error == OTA_END_ERROR) Serial.println("Falha no Fim");
});
ArduinoOTA.begin();
Serial.println("Pronto");
Serial.print("Endereco IP: ");
Serial.println(WiFi.localIP());
}
// ----------------------------------------------------------------------------------------------- //
void loop() {
ArduinoOTA.handle(); // OTA handle
int A,B;
timeClient.update();
display.setBrightness(7); // Set the brightness:
A = timeClient.getHours() * 100 + timeClient.getMinutes();
B = timeClient.getSeconds();
if((B % 2) == 0)
{display.showNumberDecEx(A, 0b01000000 , false, 4, 0);}
else
{display.showNumberDecEx(A, 0b00000000 , false, 4, 0);}
}