LCD clock display set using NTP server
Dependencies: EthernetNetIf NTPClient_NetServices TextLCD mbed
Fork of Internet_LCD_Clock by
Internet_LCD_Clock.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "NTPClient.h" 00004 #include "TextLCD.h" 00005 // Internet of Things clock example: LCD time is set via internet NTP time server 00006 TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3 00007 EthernetNetIf eth; 00008 NTPClient ntp; 00009 00010 int main() { 00011 //system time structure 00012 time_t ctTime; 00013 //clear LCD 00014 lcd.cls(); 00015 // lcd.printf prints to LCD display; 00016 lcd.printf("Get IP addr..."); 00017 EthernetErr ethErr = eth.setup(); 00018 //Get an Internet IP address using DHCP 00019 if (ethErr) { 00020 //error or timeout getting an IP address 00021 lcd.cls(); 00022 lcd.printf("Network Error \n\r %d",ethErr); 00023 return -1; 00024 } 00025 lcd.cls(); 00026 lcd.printf("Reading Time...\n\r"); 00027 //specify time server URL 00028 Host server(IpAddr(), 123, "0.uk.pool.ntp.org"); 00029 //Read time from server 00030 ntp.setTime(server); 00031 lcd.printf("Time set"); 00032 //Delay for human time to read LCD display 00033 wait(1); 00034 while (1) { 00035 // loop and periodically update the LCD's time display 00036 lcd.cls(); 00037 ctTime = time(NULL); 00038 lcd.printf("UTC: %s", ctime(&ctTime)); 00039 printf("Current time is (UTC): %s\n", ctime(&ctTime)); 00040 wait(.25); 00041 } 00042 }
Generated on Wed Jul 13 2022 02:51:27 by 1.7.2