copy of rtc example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "LowPowerTimer.h"
00003 #include "arm_math.h"
00004 DigitalOut myled(LED1);
00005 
00006 int main() {
00007     Serial      pc(PA_9, PA_10, 115200);
00008     pc.printf("RTC example\n"); 
00009     set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
00010     LowPowerTimer lp;
00011     AnalogIn ai(PA_6);
00012     Timer p2;
00013     p2.start();
00014     lp.start();
00015     pc.printf("Date and time are set.\n");
00016 unsigned int i = 0;
00017     while(1) {
00018 
00019         //time_t seconds = time(NULL);
00020 
00021         //printf("Time as seconds since January 1, 1970 = %d\n", seconds);
00022         //float nowms = abs(lp.read_us());
00023         //float insin = sqrt(nowms);
00024         myled = 1;   
00025         
00026 
00027         //char buffer[32];
00028         //strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
00029         //printf("Time as a custom formatted string = %s", buffer);
00030         wait_us(1);
00031         myled = 0;
00032         for(int j = 0; j < 50; ++j){
00033         pc.printf("{\"data\":\"%d\",\"val\":%4.2f}\n", ++i, (float)(ai.read()*3.3f));
00034         wait(0.1);
00035         }
00036         
00037     }
00038 }