Display the date and time using RTC.

Dependencies:   mbed

Committer:
arostm
Date:
Wed Jun 07 12:53:31 2017 +0000
Revision:
1:361a24c01ed7
Parent:
0:bad75bd13618
Adding new mbed library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:bad75bd13618 1 #include "mbed.h"
bcostm 0:bad75bd13618 2
bcostm 0:bad75bd13618 3 DigitalOut myled(LED1);
bcostm 0:bad75bd13618 4
bcostm 0:bad75bd13618 5 int main() {
bcostm 0:bad75bd13618 6
bcostm 0:bad75bd13618 7 printf("RTC example\n");
bcostm 0:bad75bd13618 8 set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
bcostm 0:bad75bd13618 9 printf("Date and time are set.\n");
bcostm 0:bad75bd13618 10
bcostm 0:bad75bd13618 11 while(1) {
bcostm 0:bad75bd13618 12
bcostm 0:bad75bd13618 13 time_t seconds = time(NULL);
bcostm 0:bad75bd13618 14
bcostm 0:bad75bd13618 15 //printf("Time as seconds since January 1, 1970 = %d\n", seconds);
bcostm 0:bad75bd13618 16
bcostm 0:bad75bd13618 17 printf("Time as a basic string = %s", ctime(&seconds));
bcostm 0:bad75bd13618 18
bcostm 0:bad75bd13618 19 //char buffer[32];
bcostm 0:bad75bd13618 20 //strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
bcostm 0:bad75bd13618 21 //printf("Time as a custom formatted string = %s", buffer);
bcostm 0:bad75bd13618 22
bcostm 0:bad75bd13618 23 myled = !myled;
bcostm 0:bad75bd13618 24 wait(1);
bcostm 0:bad75bd13618 25 }
bcostm 0:bad75bd13618 26 }