I made the digital watch which set the start time in ntp. It\'s same as \"clock\" see:[http://mbed.org/users/jf1vrr/programs/clock/lpucqk] except that I changed from unix timezone to ntp. See: http://blogs.yahoo.co.jp/jf1vrr_station/19816010.html (Japanese)
Dependencies: EthernetNetIf NTPClient_NetServices TextLCD mbed
main.cpp
00001 /* I made the digital watch which set the start time in ntp. 00002 It's same as "clock" see:[http://mbed.org/users/jf1vrr/programs/clock/lpucqk] 00003 except that I changed from unix timezone to ntp. 00004 */ 00005 #include "mbed.h" 00006 #include "TextLCD.h" 00007 #include "EthernetNetIf.h" 00008 #include "NTPClient.h" 00009 00010 TextLCD lcd(p24, p26, p27, p28, p29, p30); 00011 EthernetNetIf eth; 00012 NTPClient ntp; 00013 00014 int offset_JAPAN = 32400; 00015 00016 int main() { 00017 /* Set up Ethernet */ 00018 lcd.cls(); 00019 lcd.printf("Setting up Eth\n"); 00020 EthernetErr ethErr = eth.setup(); 00021 if (ethErr) { 00022 lcd.cls(); 00023 lcd.printf("Error with Eth\nNum: %d", ethErr); 00024 return -1; 00025 } 00026 00027 /* Set up NTP */ 00028 lcd.printf("Setting up NTP\n"); 00029 Host server(IpAddr(), 123, "ntp1.jst.mfeed.ad.jp"); 00030 ntp.setTime(server); 00031 00032 lcd.cls(); 00033 while(1) { 00034 time_t seconds = time(NULL)+offset_JAPAN; 00035 00036 lcd.locate(0,0); 00037 char day[16]; 00038 strftime(day, 16, "%Y/%m/%d %a\n", localtime(&seconds)); 00039 lcd.printf("%s", day); 00040 00041 char time[16]; 00042 strftime(time, 16, "%H:%M:%S\n", localtime(&seconds)); 00043 lcd.locate(0,1); 00044 lcd.printf("%s", time); 00045 00046 wait(1.0); 00047 } 00048 }
Generated on Sat Jul 16 2022 13:23:19 by 1.7.2