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.

Dependents:   Clock_Hello

See demo:

Import programClock_Hello

Demo for the Clock library (real time clock driven by a Ticker).

Committer:
hudakz
Date:
Thu Apr 30 10:22:17 2015 +0000
Revision:
0:af43d5d263e7
Child:
1:0668893c1c6f
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:af43d5d263e7 1 /*
hudakz 0:af43d5d263e7 2 Clock.h
hudakz 0:af43d5d263e7 3
hudakz 0:af43d5d263e7 4 Created on: Mar 24, 2015
hudakz 0:af43d5d263e7 5 Author: Zoltan Hudak
hudakz 0:af43d5d263e7 6
hudakz 0:af43d5d263e7 7 Copyright (c) 2015 Zoltan Hudak <hudakz@inbox.com>
hudakz 0:af43d5d263e7 8 All rights reserved.
hudakz 0:af43d5d263e7 9
hudakz 0:af43d5d263e7 10 This program is free software: you can redistribute it and/or modify
hudakz 0:af43d5d263e7 11 it under the terms of the GNU General Public License as published by
hudakz 0:af43d5d263e7 12 the Free Software Foundation, either version 3 of the License, or
hudakz 0:af43d5d263e7 13 (at your option) any later version.
hudakz 0:af43d5d263e7 14
hudakz 0:af43d5d263e7 15 This program is distributed in the hope that it will be useful,
hudakz 0:af43d5d263e7 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 0:af43d5d263e7 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
hudakz 0:af43d5d263e7 18 GNU General Public License for more details.
hudakz 0:af43d5d263e7 19
hudakz 0:af43d5d263e7 20 You should have received a copy of the GNU General Public License
hudakz 0:af43d5d263e7 21 along with this program. If not, see <http://www.gnu.org/licenses/>.
hudakz 0:af43d5d263e7 22 */
hudakz 0:af43d5d263e7 23
hudakz 0:af43d5d263e7 24 #ifndef Clock_H_
hudakz 0:af43d5d263e7 25 #define Clock_H_
hudakz 0:af43d5d263e7 26
hudakz 0:af43d5d263e7 27 #include "mbed.h"
hudakz 0:af43d5d263e7 28
hudakz 0:af43d5d263e7 29 typedef void (*ClockFnc_t) (void);
hudakz 0:af43d5d263e7 30
hudakz 0:af43d5d263e7 31 class Clock
hudakz 0:af43d5d263e7 32 {
hudakz 0:af43d5d263e7 33 Ticker _ticker;
hudakz 0:af43d5d263e7 34 static time_t _time;
hudakz 0:af43d5d263e7 35 static struct tm _tm;
hudakz 0:af43d5d263e7 36
hudakz 0:af43d5d263e7 37 static ClockFnc_t _onTick;
hudakz 0:af43d5d263e7 38
hudakz 0:af43d5d263e7 39 public:
hudakz 0:af43d5d263e7 40
hudakz 0:af43d5d263e7 41 Clock(int year, int mon, int mday, int hour, int min, int sec);
hudakz 0:af43d5d263e7 42 Clock();
hudakz 0:af43d5d263e7 43 void set(int year, int mon, int mday, int hour, int min, int sec);
hudakz 0:af43d5d263e7 44 void set(tm& val);
hudakz 0:af43d5d263e7 45 static time_t time();
hudakz 0:af43d5d263e7 46 int year(void);
hudakz 0:af43d5d263e7 47 int mon(void);
hudakz 0:af43d5d263e7 48 int mday(void);
hudakz 0:af43d5d263e7 49 int hour(void);
hudakz 0:af43d5d263e7 50 int min(void);
hudakz 0:af43d5d263e7 51 int sec(void);
hudakz 0:af43d5d263e7 52 static void tick(void);
hudakz 0:af43d5d263e7 53 void attach(ClockFnc_t fnc);
hudakz 0:af43d5d263e7 54 void detach();
hudakz 0:af43d5d263e7 55 static time_t asTime(int year, int mon, int mday, int hour, int min, int sec);
hudakz 0:af43d5d263e7 56 };
hudakz 0:af43d5d263e7 57 #endif /* Clock_H_ */