Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Example to setup the Real-Time Clock from a terminal, sford
00002 
00003 #include "mbed.h"
00004 
00005 int main() {
00006 
00007     // get the current time from the terminal
00008     struct tm t;
00009     printf("Enter current date and time:\n");
00010     printf("YYYY MM DD HH MM SS[enter]\n");    
00011     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);
00012 
00013     // adjust for tm structure required values
00014     t.tm_year = t.tm_year - 1900;
00015     t.tm_mon = t.tm_mon - 1;
00016     
00017     // set the time
00018     set_time(mktime(&t));
00019         
00020     // display the time
00021     while(1) {    
00022         time_t seconds = time(NULL);
00023         printf("Time as a basic string = %s", ctime(&seconds));
00024         wait(1);
00025     }
00026 }