n-Bed testing

Dependencies:   mbed

Fork of set_time_example2 by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

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