2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: sample.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: sample demo stopwatch class
|
|
|
|
// DATE: 2011-01-04
|
|
|
|
// URL: https://github.com/RobTillaart/StopWatch_RT
|
2021-12-28 11:04:43 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
#include <StopWatch.h>
|
|
|
|
|
2021-12-28 11:04:43 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
StopWatch MySW;
|
|
|
|
StopWatch SWarray[5];
|
|
|
|
|
2021-12-28 11:04:43 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("Stopwatch demo");
|
|
|
|
Serial.print("Version: ");
|
|
|
|
Serial.println(STOPWATCH_LIB_VERSION);
|
|
|
|
|
|
|
|
SWarray[0].start();
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:04:43 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
Serial.println(MySW.isRunning());
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
MySW.start();
|
2021-12-28 11:04:43 -05:00
|
|
|
Serial.println(MySW.isRunning());
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println("START 1");
|
|
|
|
for(int i=0; i<5; i++)
|
|
|
|
{
|
|
|
|
delay(10);
|
|
|
|
Serial.println(MySW.elapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
MySW.stop();
|
|
|
|
Serial.println(MySW.isRunning());
|
|
|
|
Serial.println("STOP");
|
|
|
|
for(int i=0; i<5; i++)
|
|
|
|
{
|
|
|
|
delay(10);
|
|
|
|
Serial.println(MySW.elapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
MySW.start();
|
2021-12-28 11:04:43 -05:00
|
|
|
Serial.println(MySW.isRunning());
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println("START 2");
|
|
|
|
for(int i=0; i<5; i++)
|
|
|
|
{
|
|
|
|
delay(10);
|
|
|
|
Serial.println(MySW.elapsed());
|
2021-12-28 11:04:43 -05:00
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
MySW.reset();
|
|
|
|
Serial.println(MySW.isRunning());
|
|
|
|
Serial.println("RESET");
|
|
|
|
|
|
|
|
MySW.start();
|
|
|
|
Serial.println(MySW.isRunning());
|
|
|
|
Serial.println("START 3");
|
|
|
|
for(int i=0; i<5; i++)
|
|
|
|
{
|
|
|
|
delay(10);
|
|
|
|
Serial.println(MySW.elapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(MySW.state())
|
|
|
|
{
|
2021-12-28 11:04:43 -05:00
|
|
|
case StopWatch::RESET:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println("reset"); // e.g. disable stop/reset
|
|
|
|
break;
|
2021-12-28 11:04:43 -05:00
|
|
|
case StopWatch::RUNNING:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println("running"); // display laptime
|
|
|
|
break;
|
2021-12-28 11:04:43 -05:00
|
|
|
case StopWatch::STOPPED:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println("stopped"); // display finaltime
|
|
|
|
break;
|
2021-12-28 11:04:43 -05:00
|
|
|
default:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println("unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(3000);
|
|
|
|
Serial.print(" >>> laptime loop() : ");
|
2021-12-28 11:04:43 -05:00
|
|
|
Serial.println(SWarray[0].elapsed());
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:04:43 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-28 11:04:43 -05:00
|
|
|
|