Go Down

Topic: Simple StopWatch class to measure elapsed time (Read 9916 times) previous topic - next topic


Jan 04, 2011, 08:23 pm Last Edit: Jan 04, 2011, 08:23 pm by robtillaart Reason: 1
Inspired by a question about resetting millis() on the forum today I developped a simple StopWatch Class. As it is a Class one can instantiate standalone stopwatches or an array of them. As it is based upon millis() it inherits some of its behavior...

The class has 5 functions and a constructor:
Code: [Select]

     StopWatch();            // constructor
     void start();            // start / continue the measurement
     void stop();            // stops the measurement
     long reset();            // reset the measurement (can't continue)
     unsigned long value();      // elapsed time since start (leaptime)
     bool isRunning();      // current state of the stopwatch

Have a look at - http://www.arduino.cc/playground/Code/StopWatchClass - for the details.

Suggestions, improvements and other comments ? let me know : enjoy tinkering

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Coding Badly

I have a suggestion... Push the implementation up into the header file.  This gives the compiler the option to inline the short methods.

Coding Badly

Jan 04, 2011, 08:41 pm Last Edit: Jan 04, 2011, 08:42 pm by bcook Reason: 1

Another suggestion... I think this can be removed from the CPP file...

#include "Wstring.h"

And the filename is probably case sensitive on *nix operating systems...

#include "[glow]w[/glow]iring.h"


Nice and well documented - thanks for sharing


Thank you for posting this and documenting it.  Nice simple library.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131