Difference between revisions of "WeMOS: D1 R1 mini NTP 7 Segmen TM1650 I2C tanpa Serial"

From OnnoWiki
Jump to navigation Jump to search
(Created page with " →‎SDA - pin D2 SCL - pin D1: #include <Wire.h> #include <TM1650.h> #include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> const char *ssid...")
 
 
Line 13: Line 13:
 
  const char *password = "Dzaq1993!";
 
  const char *password = "Dzaq1993!";
 
  const long utcOffsetInSeconds = 25200;
 
  const long utcOffsetInSeconds = 25200;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
 
   
 
   
 
  TM1650 d;
 
  TM1650 d;
Line 19: Line 18:
 
  // Define NTP Client to get time
 
  // Define NTP Client to get time
 
  WiFiUDP ntpUDP;
 
  WiFiUDP ntpUDP;
  NTPClient timeClient(ntpUDP, "asia.pool.ntp.org", utcOffsetInSeconds);
+
  NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
 
  int hh, mm, ss;
 
  int hh, mm, ss;
 
  char cWaktu[5];
 
  char cWaktu[5];
Line 26: Line 25:
 
  {
 
  {
 
   Wire.begin(); //Join the bus as master
 
   Wire.begin(); //Join the bus as master
+
   d.init();  
  Serial.begin(115200); //Start serial communication at 9600 for debug statements
 
  Serial.println("TM1650 Example Code");
 
 
   d.init();
 
 
   
 
   
 
   Serial.begin(115200);
 
   Serial.begin(115200);
Line 36: Line 31:
 
   while ( WiFi.status() != WL_CONNECTED ) {
 
   while ( WiFi.status() != WL_CONNECTED ) {
 
     delay ( 500 );
 
     delay ( 500 );
    Serial.print ( "." );
 
 
   }
 
   }
 
   timeClient.begin();
 
   timeClient.begin();
 
  }
 
  }
 
+
 
  void loop() {
 
  void loop() {
 
   timeClient.update();
 
   timeClient.update();
 
   hh = timeClient.getHours();
 
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
+
   mm = timeClient.getMinutes();  
  ss = timeClient.getSeconds();
 
 
   
 
   
 
   if ( hh>9 ) {
 
   if ( hh>9 ) {
Line 51: Line 44:
 
     temp_str.toCharArray(cWaktu,5);
 
     temp_str.toCharArray(cWaktu,5);
 
   } else {
 
   } else {
     String temp_str = String( 0 ) + String( hh*100 + mm );
+
     String temp_str = " " + String( hh*100 + mm );
     temp_str.toCharArray(cWaktu,5);  
+
     temp_str.toCharArray(cWaktu,5);
   }
+
   }  
 
   
 
   
 
   d.displayString( cWaktu ); // menampilkan waktu
 
   d.displayString( cWaktu ); // menampilkan waktu
   delay(500); // tunggu selama 1 detik
+
   delay(500); // tunggu selama 1 detik  
 
   
 
   
 
   for (int i = 0; i<20; i++) {
 
   for (int i = 0; i<20; i++) {
Line 68: Line 61:
 
     }
 
     }
 
   }
 
   }
 +
 
 
  }
 
  }

Latest revision as of 01:12, 26 March 2023

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