Difference between revisions of "WeMOS: D1 R1 mini NTP 7 Segmen TM1650 I2C tanpa Serial"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) (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...") |
Onnowpurbo (talk | contribs) |
||
Line 13: | Line 13: | ||
const char *password = "Dzaq1993!"; | const char *password = "Dzaq1993!"; | ||
const long utcOffsetInSeconds = 25200; | const long utcOffsetInSeconds = 25200; | ||
− | |||
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, " | + | 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(); | |
− | |||
− | |||
− | |||
− | 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 ); | ||
− | |||
} | } | ||
timeClient.begin(); | timeClient.begin(); | ||
} | } | ||
− | + | ||
void loop() { | void loop() { | ||
timeClient.update(); | timeClient.update(); | ||
hh = timeClient.getHours(); | hh = timeClient.getHours(); | ||
− | mm = timeClient.getMinutes | + | mm = timeClient.getMinutes(); |
− | |||
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 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); } } }