Difference between revisions of "WeMOS: NTP Jam Digital 7 Segmen Display"

From OnnoWiki
Jump to navigation Jump to search
(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...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
 +
sudo su
 +
cd ~/Arduino/libraries
 +
rm master.zip
 +
wget https://github.com/arduino-libraries/NTPClient/archive/master.zip
 +
unzip master.zip
 +
 +
==Source Code==
 +
 
  #include <NTPClient.h>
 
  #include <NTPClient.h>
 
  #include <ESP8266WiFi.h>
 
  #include <ESP8266WiFi.h>
Line 5: Line 14:
 
  #include <TM1650.h>
 
  #include <TM1650.h>
 
   
 
   
  const char *ssid    = "HUAWEI-1A73";
+
  const char *ssid    = "ssid";
  const char *password = "52408495";
+
  const char *password = "password";
 
   
 
   
 
  const long utcOffsetInSeconds = 3600;   
 
  const long utcOffsetInSeconds = 3600;   
Line 33: Line 42:
  
 
  void loop() {
 
  void loop() {
   char waktu[];
+
   char waktu[5];
 
   timeClient.update();  
 
   timeClient.update();  
 
    
 
    

Latest revision as of 05:46, 27 July 2020

sudo su
cd ~/Arduino/libraries
rm master.zip
wget https://github.com/arduino-libraries/NTPClient/archive/master.zip
unzip master.zip

Source Code

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

const char *ssid     = "ssid";
const char *password = "password";

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[5];
  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);
  }
}