It is a simple clock that used TextLCD and NTP Client.
Dependencies: mbed NetEthApiLPC1768 NetServicesLPC1768
SimpleLCDClock.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "NtpClient.h" 00004 #include "TextLCD.h" 00005 00006 TextLCD lcd(p6, p8, p13, p14, p15, p16); // rs, e, d0, d1, d2, d3 00007 00008 EthernetNetIf eth; 00009 NtpClient ntp; 00010 00011 int main() { 00012 char buf[40]; 00013 printf("\r\nSetting up...\r\n"); 00014 lcd.printf("Setting up...\n"); 00015 EthernetErr ethErr = eth.setup(); 00016 if (ethErr) { 00017 printf("Error %d in setup.\n", ethErr); 00018 lcd.printf("Error %d in setup.\n", ethErr); 00019 return -1; 00020 } 00021 printf("\r\nSetup OK\r\n"); 00022 00023 time_t ctTime; 00024 ctTime = time(NULL); 00025 00026 printf("\r\nCurrent time is : %s JST\r\n", ctime(&ctTime)); 00027 lcd.printf("Timer setting...\n"); 00028 Host server(IpAddr(), 123, "ntp.jst.mfeed.ad.jp"); 00029 ntp.setTime(server); 00030 00031 ctTime = time(NULL); 00032 ctTime += 32400; //set jst time 00033 strftime(buf,sizeof(buf), "%A %m/%d/%Y %H:%M:%S\n", localtime(&ctTime)); 00034 printf("\r\nTime is now : %s JST\r\n", buf); 00035 00036 while (1) { 00037 lcd.cls(); 00038 ctTime = time(NULL); 00039 ctTime += 32400; 00040 strftime(buf,sizeof(buf), "%Y/%m/%d %a \n%H:%M:%S", localtime(&ctTime)); 00041 printf("%s\n", buf); 00042 lcd.printf("%s", buf); 00043 00044 wait(1); 00045 } 00046 00047 return 0; 00048 00049 }
Generated on Fri Jul 15 2022 12:41:18 by 1.7.2