Software implemented real time clock driven by a Ticker. No external hardware (like DS1307 or DS3231 or etc.) is needed. Should work on any mbed platform where Ticker works.
See demo:
Import programClock_Hello
Demo for the Clock library (real time clock driven by a Ticker).
Diff: Clock.cpp
- Revision:
- 2:a18375196723
- Parent:
- 1:0668893c1c6f
- Child:
- 3:58f5afbd24cd
--- a/Clock.cpp Sat Oct 24 11:19:24 2015 +0000 +++ b/Clock.cpp Sat Nov 21 10:00:28 2015 +0000 @@ -49,8 +49,8 @@ */ Clock::Clock(int year, int mon, int mday, int hour, int min, int sec) { _ticker.attach(&tick, 1.0); // a Ticker ticking at 1s rate - set(year, mon, mday, hour, min, sec); // set date and time - attach_rtc(time, NULL, NULL, NULL); // attach Clock to be used for the C time functions + set(year, mon, mday, hour, min, sec); // set date and time as requested + attach_rtc(time, NULL, NULL, NULL); // attach for C time functions } /** @@ -58,14 +58,14 @@ * @note The clock is driven by a Ticker. * Since the Clock is attached as an external RTC * standard C time functions can be called as well. - * Time is set to the begin of Epoche: 00:00:00 January 1, 1970 + * Time is set to the begin of Epoch: 00:00:00 January 1, 1970 * @param * @retval */ Clock::Clock() { _ticker.attach(&tick, 1.0); // a Ticker ticking at 1s rate - set(1970, 1, 1, 0, 0, 0); // set date and time to the begin of Epoche - attach_rtc(time, NULL, NULL, NULL); // attach Clock to be used for the C time functions + set(1970, 1, 1, 0, 0, 0); // set date and time to the begin of Epoch + attach_rtc(time, NULL, NULL, NULL); // attach for C time functions } /** @@ -117,7 +117,6 @@ void Clock::set(time_t val) { _ticker.detach(); // suspend ticks _time = val; - _tm = *localtime(&val); _tm = *::localtime(&_time); _ticker.attach(&tick, 1.0); // renew ticks }