Arduino_BlinkWithoutDelay_RTC sample code ported. It needs an RTC crystal to be soldered on the board.
Fork of RTC_tst by
main.cpp@1:742882520852, 2014-09-03 (annotated)
- Committer:
- homayoun
- Date:
- Wed Sep 03 10:26:52 2014 +0000
- Revision:
- 1:742882520852
- Parent:
- 0:9fac448e0530
Arduino_BlinkWithoutDelay_RTC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:9fac448e0530 | 1 | #include "mbed.h" |
kenjiArai | 0:9fac448e0530 | 2 | |
homayoun | 1:742882520852 | 3 | DigitalOut myled(LED1); // Assign LED1 output port |
homayoun | 1:742882520852 | 4 | time_t previousSeconds; |
homayoun | 1:742882520852 | 5 | long interval = 1; |
kenjiArai | 0:9fac448e0530 | 6 | |
homayoun | 1:742882520852 | 7 | void setup() |
homayoun | 1:742882520852 | 8 | { |
homayoun | 1:742882520852 | 9 | // setup time structure for 26 August 2014 00:00:00 |
kenjiArai | 0:9fac448e0530 | 10 | struct tm t; |
kenjiArai | 0:9fac448e0530 | 11 | t.tm_sec = 00; // 0-59 |
homayoun | 1:742882520852 | 12 | t.tm_min = 00; // 0-59 |
homayoun | 1:742882520852 | 13 | t.tm_hour = 00; // 0-23 |
homayoun | 1:742882520852 | 14 | t.tm_mday = 26; // 1-31 |
homayoun | 1:742882520852 | 15 | t.tm_mon = 8; // 0-11 |
homayoun | 1:742882520852 | 16 | t.tm_year = 114; // year since 1900 |
homayoun | 1:742882520852 | 17 | |
homayoun | 1:742882520852 | 18 | time_t seconds = mktime(&t); |
kenjiArai | 0:9fac448e0530 | 19 | set_time(seconds); |
homayoun | 1:742882520852 | 20 | previousSeconds = seconds; |
homayoun | 1:742882520852 | 21 | } |
homayoun | 1:742882520852 | 22 | |
homayoun | 1:742882520852 | 23 | void loop() |
homayoun | 1:742882520852 | 24 | { |
homayoun | 1:742882520852 | 25 | time_t currentSeconds = time(NULL); |
homayoun | 1:742882520852 | 26 | if(currentSeconds - previousSeconds > interval) { |
homayoun | 1:742882520852 | 27 | previousSeconds = currentSeconds; // save the last time you blinked the LED |
homayoun | 1:742882520852 | 28 | myled = !myled; |
kenjiArai | 0:9fac448e0530 | 29 | } |
kenjiArai | 0:9fac448e0530 | 30 | } |
kenjiArai | 0:9fac448e0530 | 31 | |
homayoun | 1:742882520852 | 32 | int main() |
homayoun | 1:742882520852 | 33 | { |
homayoun | 1:742882520852 | 34 | setup(); |
homayoun | 1:742882520852 | 35 | while(1) loop(); |
homayoun | 1:742882520852 | 36 | } |
homayoun | 1:742882520852 | 37 | |
homayoun | 1:742882520852 | 38 |