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.h
- Revision:
- 5:d65fc7060635
- Parent:
- 3:58f5afbd24cd
- Child:
- 6:7edabed68b0f
diff -r bbe7d7474acd -r d65fc7060635 Clock.h --- a/Clock.h Fri Apr 01 07:23:02 2016 +0000 +++ b/Clock.h Fri May 20 18:14:34 2016 +0000 @@ -26,15 +26,15 @@ #include "mbed.h" -typedef void (*ClockFnc_t) (void); - class Clock { - Ticker _ticker; - static time_t _time; - static struct tm _tm; + Ticker _ticker; + static time_t _time; + static struct tm _tm; - static ClockFnc_t _onTick; +protected: + + static FunctionPointer _onTick; public: @@ -52,8 +52,13 @@ int min(void); int sec(void); static void tick(void); - void attach(ClockFnc_t fnc); - void detach(); static time_t asTime(int year, int mon, int mday, int hour, int min, int sec); + void attach(void (*fptr)(void)); + void detach(); + template<typename T> + void attach(T* tptr, void (T::*mptr)(void)) { + if((tptr != NULL) && (mptr != NULL)) + _onTick.attach(tptr, mptr); + } }; #endif /* Clock_H_ */