Nathan Yonkee
/
Nucleo_display_time
copy of rtc example
main.cpp@2:b3aa9dd045be, 2018-02-06 (annotated)
- Committer:
- tulanthoar
- Date:
- Tue Feb 06 07:19:24 2018 +0000
- Revision:
- 2:b3aa9dd045be
- Parent:
- 0:32f1960de3fb
import to local repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tulanthoar | 0:32f1960de3fb | 1 | #include "mbed.h" |
tulanthoar | 2:b3aa9dd045be | 2 | #include "LowPowerTimer.h" |
tulanthoar | 2:b3aa9dd045be | 3 | #include "arm_math.h" |
tulanthoar | 0:32f1960de3fb | 4 | DigitalOut myled(LED1); |
tulanthoar | 0:32f1960de3fb | 5 | |
tulanthoar | 0:32f1960de3fb | 6 | int main() { |
tulanthoar | 2:b3aa9dd045be | 7 | Serial pc(PA_9, PA_10, 115200); |
tulanthoar | 2:b3aa9dd045be | 8 | pc.printf("RTC example\n"); |
tulanthoar | 0:32f1960de3fb | 9 | set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC |
tulanthoar | 2:b3aa9dd045be | 10 | LowPowerTimer lp; |
tulanthoar | 2:b3aa9dd045be | 11 | AnalogIn ai(PA_6); |
tulanthoar | 2:b3aa9dd045be | 12 | Timer p2; |
tulanthoar | 2:b3aa9dd045be | 13 | p2.start(); |
tulanthoar | 2:b3aa9dd045be | 14 | lp.start(); |
tulanthoar | 2:b3aa9dd045be | 15 | pc.printf("Date and time are set.\n"); |
tulanthoar | 2:b3aa9dd045be | 16 | unsigned int i = 0; |
tulanthoar | 0:32f1960de3fb | 17 | while(1) { |
tulanthoar | 0:32f1960de3fb | 18 | |
tulanthoar | 2:b3aa9dd045be | 19 | //time_t seconds = time(NULL); |
tulanthoar | 0:32f1960de3fb | 20 | |
tulanthoar | 0:32f1960de3fb | 21 | //printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
tulanthoar | 2:b3aa9dd045be | 22 | //float nowms = abs(lp.read_us()); |
tulanthoar | 2:b3aa9dd045be | 23 | //float insin = sqrt(nowms); |
tulanthoar | 2:b3aa9dd045be | 24 | myled = 1; |
tulanthoar | 0:32f1960de3fb | 25 | |
tulanthoar | 0:32f1960de3fb | 26 | |
tulanthoar | 0:32f1960de3fb | 27 | //char buffer[32]; |
tulanthoar | 0:32f1960de3fb | 28 | //strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds)); |
tulanthoar | 0:32f1960de3fb | 29 | //printf("Time as a custom formatted string = %s", buffer); |
tulanthoar | 2:b3aa9dd045be | 30 | wait_us(1); |
tulanthoar | 2:b3aa9dd045be | 31 | myled = 0; |
tulanthoar | 2:b3aa9dd045be | 32 | for(int j = 0; j < 50; ++j){ |
tulanthoar | 2:b3aa9dd045be | 33 | pc.printf("{\"data\":\"%d\",\"val\":%4.2f}\n", ++i, (float)(ai.read()*3.3f)); |
tulanthoar | 2:b3aa9dd045be | 34 | wait(0.1); |
tulanthoar | 2:b3aa9dd045be | 35 | } |
tulanthoar | 2:b3aa9dd045be | 36 | |
tulanthoar | 0:32f1960de3fb | 37 | } |
tulanthoar | 0:32f1960de3fb | 38 | } |