WeMOS: NTP Jam Digital 7 Segmen Display

From OnnoWiki
Revision as of 11:27, 12 February 2020 by Onnowpurbo (talk | contribs) (Created page with " #include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> #include <Wire.h> #include <TM1650.h> const char *ssid = "HUAWEI-1A73"; const char *password...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <TM1650.h>

const char *ssid     = "HUAWEI-1A73";
const char *password = "52408495";

const long utcOffsetInSeconds = 3600;  

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
TM1650 d;

void setup(){
  Serial.begin(115200); 
  Wire.begin(); //Join the bus as master

  WiFi.begin(ssid, password); 

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }  

  timeClient.begin();
  d.init();
}
void loop() {
  char waktu[];
  timeClient.update(); 
  
  Serial.print(daysOfTheWeek[timeClient.getDay()]);
  Serial.print(", ");
  Serial.print(timeClient.getHours()+6);
  Serial.print(":");
  Serial.print(timeClient.getMinutes());
  Serial.print(":");
  Serial.println(timeClient.getSeconds());
  //Serial.println(timeClient.getFormattedTime());

  itoa( 100*(timeClient.getHours()+6) + timeClient.getMinutes(), waktu, 10);
  d.displayOn();
  d.displayString(waktu);
  delay(1000);

  for (int i = 0; i<5; i++) {
    d.setDot(i,true);
    delay(100);
    d.setDot(i,false);
    delay(100);
  }
}