Library for a timer that can go for days (but only ms resolution)

Dependents:   ExtendedTimer_Example FindingTemp Final_NSR NearSpaceOzoneSensor ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ExtendedTimer.h Source File

ExtendedTimer.h

00001 #ifndef EXTENDED_TIMER_H
00002 #define EXTENDED_TIMER_H
00003 
00004 #include "mbed.h"
00005 
00006 /** A timer appropriate for intervals up to about 20 days
00007  *
00008  *  @author John M. Larkin (jlarkin@whitworth.edu)
00009  *  @version 0.1
00010  *  @date 2017
00011  *  @copyright GNU Public License
00012  */
00013 
00014 class ExtendedTimer {
00015 
00016 public:
00017     ExtendedTimer();
00018     
00019     /** Start the timer        
00020     */
00021     void start();
00022     
00023     /** Stop the timer
00024     */
00025     void stop();
00026     
00027     /** Reset the timer to 0
00028     *
00029     *  If it was already counting, it will continue
00030     */
00031     void reset();
00032 
00033     /** Get the time passed in milliseconds
00034     */
00035     int read_ms();
00036     
00037     /** Get the time passed in seconds
00038     */
00039     float read();
00040     
00041     /** An operator shorthand for read()
00042     */
00043     operator float();
00044     
00045 
00046     
00047 protected:
00048     int _running; // whether the timer is running
00049     unsigned int _time; // any accumulated time from previous slices
00050     Timer usTimer;
00051     Ticker usTimerWatch;
00052     void usTimerReset();
00053 };
00054 #endif