WeMOS: D1 R1 mini NTP 7 Segmen TM1650 I2C tanpa Serial

From OnnoWiki
Jump to navigation Jump to search
/*
  SDA - pin D2
  SCL - pin D1
*/

#include <Wire.h>
#include <TM1650.h>
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char *ssid     = "o3";
const char *password = "Dzaq1993!";
const long utcOffsetInSeconds = 25200;

TM1650 d;

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
int hh, mm, ss;
char cWaktu[5];

void setup() 
{
  Wire.begin(); //Join the bus as master
  d.init(); 

  Serial.begin(115200);
  WiFi.begin(ssid, password); 
  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
  }
  timeClient.begin();
}

void loop() {
  timeClient.update();
  hh = timeClient.getHours();
  mm = timeClient.getMinutes(); 

  if ( hh>9 ) {
    String temp_str = String( hh*100 + mm );
    temp_str.toCharArray(cWaktu,5);
  } else {
    String temp_str = " " + String( hh*100 + mm );
    temp_str.toCharArray(cWaktu,5);
  } 

  d.displayString( cWaktu ); // menampilkan waktu
  delay(500); // tunggu selama 1 detik 

  for (int i = 0; i<20; i++) {
    for (int j = 0; j<4; j++) {
       d.setDot(j,true);
       delay(200);
    }
    for (int j = 0; j<4; j++) {
       d.setDot(j,false);
       delay(200);
    }
  }
  
}