thunchanok phutthaphaiboon
/
ReadRTC_example
version 1
Diff: main.cpp
- Revision:
- 0:29a6f70f93c3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 11 13:09:16 2017 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "string.h" +#include "SDFileSystem.h" + +void ReadRTC(); //DONE +void SetTime(); //DONE + +//---TIME---// +int sec = 0; +int min = 0; +int hour = 0; +int date = 0; +int month = 0; +int year = 0; + +int main() +{ + //SetTime(); + while(true) { + ReadRTC(); + printf("%d %d %d %d %d %d \n",year , month, date, hour, min, sec); + } +} + +void ReadRTC() +{ + printf(">>> ReadRTC()\n"); + struct tm * timeinfo; + char str_sec[5]; + char str_min[5]; + char str_hour[5]; + char str_date[5]; + char str_month[5]; + char str_year[5]; + time_t rawtime; + time (&rawtime); + timeinfo = localtime(&rawtime); + strftime(str_year,5,"%Y",timeinfo); + strftime(str_month,5,"%m",timeinfo); + strftime(str_date,5,"%d",timeinfo); + strftime(str_hour,5,"%H",timeinfo); + strftime(str_min,5,"%M",timeinfo); + strftime(str_sec,5,"%S",timeinfo); + sec = atoi(str_sec); + min = atoi(str_min); + hour = atoi(str_hour); + date = atoi(str_date); + month = atoi(str_month); + year = atoi(str_year); +} + +void SetTime() +{ + set_time(1513036800); +} \ No newline at end of file