![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp@0:aa559da1f84e, 2011-08-22 (annotated)
- Committer:
- gbeardall
- Date:
- Mon Aug 22 14:03:18 2011 +0000
- Revision:
- 0:aa559da1f84e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gbeardall | 0:aa559da1f84e | 1 | #include "mbed.h" |
gbeardall | 0:aa559da1f84e | 2 | |
gbeardall | 0:aa559da1f84e | 3 | DigitalOut myled(LED1); |
gbeardall | 0:aa559da1f84e | 4 | |
gbeardall | 0:aa559da1f84e | 5 | Serial pc(USBTX,USBRX); |
gbeardall | 0:aa559da1f84e | 6 | |
gbeardall | 0:aa559da1f84e | 7 | int main() { |
gbeardall | 0:aa559da1f84e | 8 | |
gbeardall | 0:aa559da1f84e | 9 | pc.printf("rtc1\n\r"); |
gbeardall | 0:aa559da1f84e | 10 | |
gbeardall | 0:aa559da1f84e | 11 | for(;;) { |
gbeardall | 0:aa559da1f84e | 12 | |
gbeardall | 0:aa559da1f84e | 13 | time_t seconds = time(NULL); |
gbeardall | 0:aa559da1f84e | 14 | |
gbeardall | 0:aa559da1f84e | 15 | char buffer[32]; |
gbeardall | 0:aa559da1f84e | 16 | strftime(buffer, 32, "%I:%M %p\n\r", localtime(&seconds)); |
gbeardall | 0:aa559da1f84e | 17 | printf("Time as a custom formatted string = %s", buffer); |
gbeardall | 0:aa559da1f84e | 18 | |
gbeardall | 0:aa559da1f84e | 19 | |
gbeardall | 0:aa559da1f84e | 20 | |
gbeardall | 0:aa559da1f84e | 21 | pc.printf("cmd:"); |
gbeardall | 0:aa559da1f84e | 22 | int c = pc.getc(); |
gbeardall | 0:aa559da1f84e | 23 | pc.printf("cmd=%d\n\r", c); |
gbeardall | 0:aa559da1f84e | 24 | |
gbeardall | 0:aa559da1f84e | 25 | switch(c) { |
gbeardall | 0:aa559da1f84e | 26 | case 's': |
gbeardall | 0:aa559da1f84e | 27 | pc.printf("set time\n\r", c); |
gbeardall | 0:aa559da1f84e | 28 | // setup time structure for Wed, 28 Oct 2009 11:35:37 |
gbeardall | 0:aa559da1f84e | 29 | struct tm t; |
gbeardall | 0:aa559da1f84e | 30 | t.tm_sec = 00; // 0-59 |
gbeardall | 0:aa559da1f84e | 31 | t.tm_min = 51; // 0-59 |
gbeardall | 0:aa559da1f84e | 32 | t.tm_hour = 22; // 0-23 |
gbeardall | 0:aa559da1f84e | 33 | t.tm_mday = 20; // 1-31 |
gbeardall | 0:aa559da1f84e | 34 | t.tm_mon = 8; // 0-11 |
gbeardall | 0:aa559da1f84e | 35 | t.tm_year = 111; // year since 1900 |
gbeardall | 0:aa559da1f84e | 36 | |
gbeardall | 0:aa559da1f84e | 37 | // convert to timestamp and display (1256729737) |
gbeardall | 0:aa559da1f84e | 38 | time_t seconds = mktime(&t); |
gbeardall | 0:aa559da1f84e | 39 | set_time(seconds); |
gbeardall | 0:aa559da1f84e | 40 | break; |
gbeardall | 0:aa559da1f84e | 41 | |
gbeardall | 0:aa559da1f84e | 42 | case 'q': |
gbeardall | 0:aa559da1f84e | 43 | pc.printf("exit\n\r", c); |
gbeardall | 0:aa559da1f84e | 44 | exit(0); |
gbeardall | 0:aa559da1f84e | 45 | |
gbeardall | 0:aa559da1f84e | 46 | } // switch |
gbeardall | 0:aa559da1f84e | 47 | |
gbeardall | 0:aa559da1f84e | 48 | } // for - evers |
gbeardall | 0:aa559da1f84e | 49 | |
gbeardall | 0:aa559da1f84e | 50 | } // main |
gbeardall | 0:aa559da1f84e | 51 |