Go Down

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

robtillaart

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

#2
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"

arduniomstr

Nice and well documented - thanks for sharing

marklar

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

Go Up