Pages: [1]   Go Down
Author Topic: Simple StopWatch class to measure elapsed time  (Read 7522 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13870
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
     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
« Last Edit: January 04, 2011, 02:23:45 pm by robtillaart » Logged

Rob Tillaart

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13030
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13030
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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"
« Last Edit: January 04, 2011, 02:42:15 pm by bcook » Logged

Oxford, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice and well documented - thanks for sharing
Logged

Florida
Offline Offline
Sr. Member
****
Karma: 4
Posts: 431
hookedup!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: