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:
- 6:7edabed68b0f
- Parent:
- 5:d65fc7060635
--- a/Clock.h Fri May 20 18:14:34 2016 +0000 +++ b/Clock.h Tue Jan 15 14:46:57 2019 +0000 @@ -4,7 +4,7 @@ Created on: Mar 24, 2015 Author: Zoltan Hudak - Copyright (c) 2015 Zoltan Hudak <hudakz@inbox.com> + Copyright (c) 2015 Zoltan Hudak <hudakz@outlook.com> All rights reserved. This program is free software: you can redistribute it and/or modify @@ -20,45 +20,37 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ - #ifndef Clock_H_ - #define Clock_H_ +#define Clock_H_ #include "mbed.h" class Clock { - Ticker _ticker; - static time_t _time; - static struct tm _tm; - + Ticker* _ticker; + static time_t _time; + static struct tm _tm; protected: - - static FunctionPointer _onTick; - + static Callback<void ()> _onTick; public: - Clock(int year, int mon, int mday, int hour, int min, int sec); Clock(); - void set(int year, int mon, int mday, int hour, int min, int sec); - void set(tm& val); - void set(time_t time); - static time_t time(); - int year(void); - int mon(void); - int mday(void); - int wday(void); - int hour(void); - int min(void); - int sec(void); - static void tick(void); - 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); - } + ~Clock(); + void set(int year, int mon, int mday, int hour, int min, int sec); + void set(tm& val); + void set(time_t time); + static time_t time(); + int year(void); + int mon(void); + int mday(void); + int wday(void); + int hour(void); + int min(void); + int sec(void); + static void tick(void); + static time_t asTime(int year, int mon, int mday, int hour, int min, int sec); + void attach(void (*fptr) (void)); + template<typename T> void attach(T* tptr, void (T:: *mptr) (void)); + void detach(); }; #endif /* Clock_H_ */