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:
- 0:af43d5d263e7
- Child:
- 1:0668893c1c6f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Clock.h Thu Apr 30 10:22:17 2015 +0000 @@ -0,0 +1,57 @@ +/* + Clock.h + + Created on: Mar 24, 2015 + Author: Zoltan Hudak + + Copyright (c) 2015 Zoltan Hudak <hudakz@inbox.com> + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + 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_ + +#include "mbed.h" + +typedef void (*ClockFnc_t) (void); + +class Clock +{ + Ticker _ticker; + static time_t _time; + static struct tm _tm; + + static ClockFnc_t _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); + static time_t time(); + int year(void); + int mon(void); + int mday(void); + int hour(void); + 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); +}; +#endif /* Clock_H_ */