n-Bed testing

Dependencies:   mbed

Fork of set_time_example2 by Simon Ford

Committer:
simon
Date:
Wed Oct 28 23:17:08 2009 +0000
Revision:
0:c635c2051b52
Child:
1:c14275b8ac8c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:c635c2051b52 1 // Example to setup the Real-Time Clock from a terminal, sford
simon 0:c635c2051b52 2
simon 0:c635c2051b52 3 #include "mbed.h"
simon 0:c635c2051b52 4
simon 0:c635c2051b52 5 int main() {
simon 0:c635c2051b52 6
simon 0:c635c2051b52 7 // get the current time from the terminal
simon 0:c635c2051b52 8 struct tm t;
simon 0:c635c2051b52 9 printf("Enter current date and time:\n");
simon 0:c635c2051b52 10 printf("YYYY MM DD HH MM SS[enter]\n");
simon 0:c635c2051b52 11 scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
simon 0:c635c2051b52 12
simon 0:c635c2051b52 13 // adjust for tm structure required values
simon 0:c635c2051b52 14 t.tm_year = t.tm_year - 1900;
simon 0:c635c2051b52 15 t.tm_mon = t.tm_mon - 1;
simon 0:c635c2051b52 16
simon 0:c635c2051b52 17 // set the time
simon 0:c635c2051b52 18 set_time(mktime(&t));
simon 0:c635c2051b52 19
simon 0:c635c2051b52 20 // display the time
simon 0:c635c2051b52 21 while(1) {
simon 0:c635c2051b52 22 time_t seconds = time(NULL);
simon 0:c635c2051b52 23 printf("Time as a basic string = %s", ctime(&seconds));
simon 0:c635c2051b52 24 wait(1);
simon 0:c635c2051b52 25 }
simon 0:c635c2051b52 26 }