#include <WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <NTPClient.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
//wifi
const char *ssid = "Wokwi-GUEST";
const char *password = "";
//ntp
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "asia.pool.ntp.org", 28800, 60000);
//led pin
//const led
const int led_red = 16; //red led on pin 19
const int led_green = 4; //red yellow on pin 18
//timesetup
const int Second = 30;
void setup() { // put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
lcd.init();
lcd.backlight();
//Setup Awal Ketika Running
lcd.setCursor(0,0);
lcd.print("test v1");
lcd.setCursor(0,1);
lcd.print("By Nasrul_2023");
delay(40);
lcd.clear();
//led pin
pinMode(led_red, OUTPUT); // initialize digital ledPin as an output.
pinMode(led_green, OUTPUT); // initialize digital ledPin as an output.
//wifi start
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 50 );
Serial.print ( "." );
}
//ntp start
timeClient.begin();
}
void loop() {
// put your main code here, to run repeatedly:
//ntp display time on lcd
timeClient.update();
Serial.println(timeClient.getFormattedTime());
//delay(1000);
lcd.setCursor(0,0);
lcd.print("Masa:");
lcd.print(timeClient.getFormattedTime());
lcd.setCursor(0,1);
lcd.print("Matrix:19DTK22Fxx");
// this speeds up the simulation
if(timeClient.isTimeSet()) {
if (Second <= timeClient.getSeconds()) {
digitalWrite(led_red, HIGH);
digitalWrite(led_green, LOW);
}
}
if(timeClient.isTimeSet()) {
if (Second > timeClient.getSeconds()) {
digitalWrite(led_red, LOW);
digitalWrite(led_green, HIGH);
}
}
delay(10);
}