Chrono

Chronometer/stopwatch library that counts the time passed since started.

Get It!

Adding Chrono

Copy the Chrono folder to your Arduino or Wiring libraries folder.

Basic Example


// INCLUDE CHRONO LIBRARY
// Documentation : https://github.com/thomasfredericks/Chrono-Arduino-Wiring/blob/master/README.md
// Download : https://github.com/thomasfredericks/Chrono-Arduino-Wiring/archive/master.zip
#include  <Chrono.h>

// Instanciate a Chrono object.
Chrono myChrono; 

void setup() {
  // Start the chronometer on setup.
  myChrono.start();
}

void loop() {
  // Check whether the chronometer has reached 1000 time units.
  if (myChrono.hasPassed(1000)) {
    // Do something here...
    // Restart the chronometer.
    myChrono.restart();
  }
}

Basic Usage

Include the library

// INCLUDE CHRONO LIBRARY : http://github.com/thomasfredericks/Chrono
#include <Chrono.h>

Create an instance

Once a Chrono is created, it starts counting (in milliseconds by default).

// CREATE A CHRONO INSTANCE :
Chrono myChrono;

Basic Methods

elapsed() unsigned long Returns the elapsed time
restart() void Starts/restarts the chronometer
hasPassed( timeout ) bool Returns true if the chronometer passed the timeout

Advanced Usage

Time units

You can create a Chrono that counts in microseconds or seconds:
Chrono myChronoMicros(SuperChrono::MICROS);
Chrono myChronoSeconds(SuperChrono::SECONDS);

Custom time function

Alternatively you can create a Chrono with a custom time function:
unsigned long mySpecialTimeFunction();

Chrono myChronoMicros(mySpecialTimeFunction);

Advanced Methods

restart( offset ) void You can alternatively start(restart) the chronometer with a time offset
stop() void Stops/pauses the chronometer
resume( ) void Resumes the chronometer
hasPassed( timeout,restartIfPassed ) bool If the chronometer passed the timeout, returns true and restarts the chronometer
add( time ) void Immediately adds some time to the chronometer
isRunning( ) bool Returns true if the chronometer is currently running
delay( time ) void Waits for some time (in the time unit of the chronometer)