WeMOS: D1 R1 mini NTP 7 Segmen TM1650 I2C

From OnnoWiki
Revision as of 00:32, 22 March 2023 by Onnowpurbo (talk | contribs)
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;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

TM1650 d;

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

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

  Serial.begin(115200); //Start serial communication at 9600 for debug statements
  Serial.println("TM1650 Example Code");

  d.init();

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

void loop() {
  timeClient.update();
  hh = timeClient.getHours();
  mm = timeClient.getMinutes();
  ss = timeClient.getSeconds();
  Serial.print(daysOfTheWeek[timeClient.getDay()]);
  Serial.print(", ");
  Serial.print(hh);
  Serial.print(":");
  Serial.print(mm);
  Serial.print(":");
  Serial.println(ss);
  // Serial.println(timeClient.getFormattedTime());
  // delay(1000); 

  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);
    }
  }
  
}