Arduino_BlinkWithoutDelay_RTC sample code ported. It needs an RTC crystal to be soldered on the board.

Dependencies:   mbed

Fork of RTC_tst by Kenji Arai

main.cpp

Committer:
homayoun
Date:
2014-09-03
Revision:
1:742882520852
Parent:
0:9fac448e0530

File content as of revision 1:742882520852:

#include "mbed.h"

DigitalOut myled(LED1);  // Assign LED1 output port
time_t previousSeconds;
long interval = 1;

void setup()
{
    // setup time structure for 26 August 2014 00:00:00
    struct tm t;
    t.tm_sec = 00;    // 0-59
    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);
    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();
}