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).

Revision:
1:0668893c1c6f
Parent:
0:af43d5d263e7
Child:
2:a18375196723
--- a/Clock.cpp	Thu Apr 30 10:22:17 2015 +0000
+++ b/Clock.cpp	Sat Oct 24 11:19:24 2015 +0000
@@ -7,7 +7,7 @@
  This is a software implemented Clock.
  No external parts are needed.
  
- For how to use have a look at <http://developer.mbed.org/users/hudakz/code/Hello_Clock/>
+ For how to use it have a look at <http://developer.mbed.org/users/hudakz/code/Hello_Clock/>
  
  Copyright (c) 2015 Zoltan Hudak <hudakz@inbox.com>
  All rights reserved.
@@ -109,6 +109,20 @@
 }
 
 /**
+ * @brief   Sets Clock to time_t value
+ * @note
+ * @param   val:    time_t structure (Number of seconds elapsed since January 1, 1970)
+ * @retval
+ */
+void Clock::set(time_t val) {
+    _ticker.detach();           // suspend ticks
+    _time = val;
+    _tm = *localtime(&val);
+    _tm = *::localtime(&_time);
+    _ticker.attach(&tick, 1.0); // renew ticks
+}
+
+/**
  * @brief   Current time
  * @note
  * @param