Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:764aaee2b395, committed 2014-07-15
- Comitter:
- morimoriYNCT
- Date:
- Tue Jul 15 04:47:11 2014 +0000
- Child:
- 1:2441ccdcd627
- Commit message:
- 24????????????????????????????????????????????????mbed???Timer????2148????????????????????????...
Changed in this revision
| TimerExtended.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TimerExtended.h Tue Jul 15 04:47:11 2014 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+
+
+class TimerExtended
+{
+private:
+ Timer _t;
+ Ticker _tk;
+ long milli_second;
+
+ void update()
+ {
+ if(this->milli_second < 2147483645)
+ this->milli_second += this->_t.read_ms();
+ this->_t.reset();
+ }
+public:
+ TimerExtended()
+ {
+ this->milli_second = 0l;
+ }
+
+ // start timer
+ void start()
+ {
+ this->_tk.attach(this, &TimerExtended::update, 2000.0); // 2000.0 should be lower then max value of Timer obj.
+ this->_t.start();
+ }
+
+ // like Arduino lib.
+ long millis()
+ {
+ (void)this->update();
+ return this->milli_second;
+ }
+
+ // return time [s] in double
+ double read()
+ {
+ return (double)this->millis() / 1000.0;
+ }
+
+ // return time [ms]
+ long read_ms()
+ {
+ return this->millis();
+ }
+
+};
\ No newline at end of file