Najia Hossain / Mbed 2 deprecated RTC_clock

Dependencies:   TextLCD mbed

Fork of clock by masa miya

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 TextLCD lcd(p24, p26, p27, p28, p29, p30);
00005 
00006 int main() {
00007      // setup time structure for Wed, 11 April 2013 5:00:00
00008     struct tm t;
00009     t.tm_sec = 00;    // 0-59
00010     t.tm_min = 00;    // 0-59
00011     t.tm_hour = 5;   // 0-23
00012     t.tm_mday = 11;   // 1-31
00013     t.tm_mon = 3;     // 0-11
00014     t.tm_year = 113;  // year since 1900
00015 
00016     // convert to timestamp 
00017     time_t seconds = mktime(&t);
00018    
00019   // Set RTC time today
00020   set_time(mktime(&t));
00021  
00022    while(1) {
00023     
00024         time_t seconds = time(NULL);
00025 
00026        lcd.locate(0,0);
00027       char day[16];
00028       strftime(day, 16, "%Y/%m/%d %a\n", localtime(&seconds));
00029       lcd.printf("%s", day);          
00030                
00031       char time[16];
00032      strftime(time, 16, "%H:%M:%S\n", localtime(&seconds));
00033      lcd.locate(0,1);
00034       lcd.printf("%s", time);
00035           
00036           
00037         wait(1.0);
00038    }
00039     
00040       
00041   
00042    
00043 }