Difference between revisions of "WeMOS: NTP Jam Digital"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) (Undo revision 57562 by Onnowpurbo (talk)) |
||
Line 1: | Line 1: | ||
==Code== | ==Code== | ||
+ | |||
#include <NTPClient.h> | #include <NTPClient.h> | ||
Line 34: | Line 35: | ||
// set up the LCD's number of columns and rows: | // set up the LCD's number of columns and rows: | ||
lcd.begin(16, 2); | lcd.begin(16, 2); | ||
+ | // Print a message to the LCD. | ||
+ | lcd.print("hello, world!"); | ||
} | } | ||
Line 41: | Line 44: | ||
// set the cursor to column 0, line 1 | // set the cursor to column 0, line 1 | ||
// (note: line 1 is the second row, since counting begins with 0): | // (note: line 1 is the second row, since counting begins with 0): | ||
− | lcd.setCursor(0, | + | lcd.setCursor(0, 1); |
− | + | // print time | |
− | |||
lcd.print(daysOfTheWeek[timeClient.getDay()]); | lcd.print(daysOfTheWeek[timeClient.getDay()]); | ||
− | + | lcd.print(", "); | |
− | lcd. | ||
lcd.print(timeClient.getHours()+6); | lcd.print(timeClient.getHours()+6); | ||
lcd.print(":"); | lcd.print(":"); | ||
lcd.print(timeClient.getMinutes()); | lcd.print(timeClient.getMinutes()); | ||
lcd.print(":"); | lcd.print(":"); | ||
− | lcd. | + | lcd.println(timeClient.getSeconds()); |
− | |||
− | |||
delay(1000); | delay(1000); | ||
} | } | ||
− | |||
− | |||
Revision as of 11:45, 23 November 2019
Code
#include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins // LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LiquidCrystal lcd(8, 9, 4, 5, 6, 7); LiquidCrystal lcd(D6, D7, D2, D3, D4, D5); 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); void setup(){ Serial.begin(115200); WiFi.begin(ssid, password); while ( WiFi.status() != WL_CONNECTED ) { delay ( 500 ); Serial.print ( "." ); } timeClient.begin(); // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); } void loop() { timeClient.update(); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print time lcd.print(daysOfTheWeek[timeClient.getDay()]); lcd.print(", "); lcd.print(timeClient.getHours()+6); lcd.print(":"); lcd.print(timeClient.getMinutes()); lcd.print(":"); lcd.println(timeClient.getSeconds()); delay(1000); }