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:
Tue Jan 15 14:46:57 2019 +0000
Revision:
6:7edabed68b0f
Parent:
5:d65fc7060635
fixed constructor, added destructor, FunctionPointer replaced with Callback

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 6:7edabed68b0f 7 Copyright (c) 2015 Zoltan Hudak <hudakz@outlook.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 #ifndef Clock_H_
hudakz 6:7edabed68b0f 24 #define Clock_H_
hudakz 0:af43d5d263e7 25
hudakz 0:af43d5d263e7 26 #include "mbed.h"
hudakz 0:af43d5d263e7 27
hudakz 0:af43d5d263e7 28 class Clock
hudakz 0:af43d5d263e7 29 {
hudakz 6:7edabed68b0f 30 Ticker* _ticker;
hudakz 6:7edabed68b0f 31 static time_t _time;
hudakz 6:7edabed68b0f 32 static struct tm _tm;
hudakz 5:d65fc7060635 33 protected:
hudakz 6:7edabed68b0f 34 static Callback<void ()> _onTick;
hudakz 0:af43d5d263e7 35 public:
hudakz 0:af43d5d263e7 36 Clock(int year, int mon, int mday, int hour, int min, int sec);
hudakz 0:af43d5d263e7 37 Clock();
hudakz 6:7edabed68b0f 38 ~Clock();
hudakz 6:7edabed68b0f 39 void set(int year, int mon, int mday, int hour, int min, int sec);
hudakz 6:7edabed68b0f 40 void set(tm& val);
hudakz 6:7edabed68b0f 41 void set(time_t time);
hudakz 6:7edabed68b0f 42 static time_t time();
hudakz 6:7edabed68b0f 43 int year(void);
hudakz 6:7edabed68b0f 44 int mon(void);
hudakz 6:7edabed68b0f 45 int mday(void);
hudakz 6:7edabed68b0f 46 int wday(void);
hudakz 6:7edabed68b0f 47 int hour(void);
hudakz 6:7edabed68b0f 48 int min(void);
hudakz 6:7edabed68b0f 49 int sec(void);
hudakz 6:7edabed68b0f 50 static void tick(void);
hudakz 6:7edabed68b0f 51 static time_t asTime(int year, int mon, int mday, int hour, int min, int sec);
hudakz 6:7edabed68b0f 52 void attach(void (*fptr) (void));
hudakz 6:7edabed68b0f 53 template<typename T> void attach(T* tptr, void (T:: *mptr) (void));
hudakz 6:7edabed68b0f 54 void detach();
hudakz 0:af43d5d263e7 55 };
hudakz 0:af43d5d263e7 56 #endif /* Clock_H_ */