LCD clock display set using NTP server
Dependencies: EthernetNetIf NTPClient_NetServices TextLCD mbed
Internet_LCD_Clock.cpp
- Committer:
- 4180_1
- Date:
- 2012-04-14
- Revision:
- 1:09fcc9b81f23
- Parent:
- 0:5c5226aac712
File content as of revision 1:09fcc9b81f23:
#include "mbed.h" #include "EthernetNetIf.h" #include "NTPClient.h" #include "TextLCD.h" // Internet of Things clock example: LCD time is set via internet NTP time server TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3 EthernetNetIf eth; NTPClient ntp; int main() { //system time structure time_t ctTime; //clear LCD lcd.cls(); // lcd.printf prints to LCD display; lcd.printf("Get IP addr..."); EthernetErr ethErr = eth.setup(); //Get an Internet IP address using DHCP if (ethErr) { //error or timeout getting an IP address lcd.cls(); lcd.printf("Network Error \n\r %d",ethErr); return -1; } lcd.cls(); lcd.printf("Reading Time...\n\r"); //specify time server URL Host server(IpAddr(), 123, "0.uk.pool.ntp.org"); //Read time from server ntp.setTime(server); lcd.printf("Time set"); //Delay for human time to read LCD display wait(1); while (1) { // loop and periodically update the LCD's time display lcd.cls(); ctTime = time(NULL); lcd.printf("UTC: %s", ctime(&ctTime)); wait(.25); } }