// https://circuitjournal.com/esp8266-with-arduino-ide

#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>

const char *ssid     = "SSID";
const char *password = "password";
int ledState = HIGH;
int Hour;
int Min_one;
int Min_ten;
int i,j ;
WiFiUDP ntpUDP;

// You can specify the time server pool and the offset (in seconds, can be
// changed later with setTimeOffset() ). Additionally you can specify the
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, "ie.pool.ntp.org", 3600, 60000);

void setup(){
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
}

void loop() {
  timeClient.update();

  Serial.println(timeClient.getFormattedTime());
Hour =  timeClient.getHours() ;
  if  (Hour > 12) {Hour= Hour-12;}
Min_ten = timeClient.getMinutes() /10 ;
Min_one =  timeClient.getMinutes() % 10 ;
if (Hour==0) {
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000); 
  }
else {
for (j= 0; j < Hour; j++){

    digitalWrite(LED_BUILTIN, LOW);
    delay(100);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(400);
  }
  delay(2000);
}
  if (Min_ten==0) {
   digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000); 
  }
  else {
for (j= 0; j < Min_ten; j++){

    digitalWrite(LED_BUILTIN, LOW);
    delay(100);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(400);
  }
  delay(2000);
  }
  if (Min_one==0) {
   digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000); 
  }
  else {
  for (j= 0; j < Min_one; j++){

    digitalWrite(LED_BUILTIN, LOW);
    delay(100);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(400);
  }
  }
  delay(5000);
  
}
