Arduino_BlinkWithoutDelay_RTC sample code ported. It needs an RTC crystal to be soldered on the board.
Fork of RTC_tst by
Diff: main.cpp
- Revision:
- 1:742882520852
- Parent:
- 0:9fac448e0530
--- a/main.cpp Sat Mar 27 07:10:12 2010 +0000 +++ b/main.cpp Wed Sep 03 10:26:52 2014 +0000 @@ -1,68 +1,38 @@ -// -// RTC Test Program -// Kenji Arai / JH1PJL -// March 27th,2010 Started -// March 27th,2010 -// #include "mbed.h" -#include "TextLCD.h" -#define TIME_KEEP_AS_IS -//#define STYLE1 -#define STYLE2 - -DigitalOut myled1(LED1); // Assign LED1 output port -TextLCD lcd(p22, p28, p27, p26, p25, p24, p23, 40, 2); // rs,rw,e,d0,d1,d2,d3,40char's x 2 lines +DigitalOut myled(LED1); // Assign LED1 output port +time_t previousSeconds; +long interval = 1; -int main() { - char buf[40]; - time_t seconds; - -#ifndef TIME_KEEP_AS_IS - // setup time structure for 27 March 2010 13:24:00 +void setup() +{ + // setup time structure for 26 August 2014 00:00:00 struct tm t; t.tm_sec = 00; // 0-59 - t.tm_min = 24; // 0-59 - t.tm_hour = 13; // 0-23 - t.tm_mday = 27; // 1-31 - t.tm_mon = 3; // 0-11 - t.tm_year = 110; // year since 1900 - seconds = mktime(&t); + t.tm_min = 00; // 0-59 + t.tm_hour = 00; // 0-23 + t.tm_mday = 26; // 1-31 + t.tm_mon = 8; // 0-11 + t.tm_year = 114; // year since 1900 + + time_t seconds = mktime(&t); set_time(seconds); -#endif - lcd.cls(); - lcd.locate(0, 0); - lcd.locate(0, 0); // 1st line top - lcd.printf("since Jan.1,1970 = %d\n", seconds); - wait(2.0); - // If you have implemented the "Windows USB Serial Port Driver", you can use follows. - // http://mbed.org/projects/handbook/wiki/WindowsSerialConfiguration - printf("\r\n Start RTC Test Program\r\n "); -#ifdef TIME_KEEP_AS_IS - printf("Defined TIME_KEEP_AS_IS\r\n"); -#else - printf("Not define TIME_KEEP_AS_IS\r\n"); -#endif - for(;;){ - myled1 = 1; - wait(0.5); - myled1 = 0; - wait(0.5); - seconds = time(NULL); - lcd.cls(); - lcd.locate(0, 0); // 1st line top - lcd.printf("It is %d sec since Jan.1,1970\n", seconds); - lcd.locate(0, 1); // 2nd line top - #ifdef STYLE1 - // 27 Mar 2010 13:24:00 - strftime(buf,40, "%x %X \n", localtime(&seconds)); - #endif - #ifdef STYLE2 - // 13:24:00 PM (2010/03/27) - strftime(buf,40, "%I:%M:%S %p (%Y/%m/%d)\n", localtime(&seconds)); - #endif - lcd.printf("Time = %s", buf); - printf("Time = %s\r", buf); + previousSeconds = seconds; +} + +void loop() +{ + time_t currentSeconds = time(NULL); + if(currentSeconds - previousSeconds > interval) { + previousSeconds = currentSeconds; // save the last time you blinked the LED + myled = !myled; } } +int main() +{ + setup(); + while(1) loop(); +} + +