#include <Plaquette.h>
/* a basic stopwatch for running or swimming */
Chronometer mainChrono; // to mark time since the program started
Chronometer lapChrono;
DigitalIn pauseButton (2, INTERNAL_PULLUP);
DigitalIn lapButton (3, INTERNAL_PULLUP);
AnalogOut runningLed (9); //led that will pulse if the lap chrono is running
Wave sine(SINE, 0.5); // wave we will send to lapLed if chrono is running
Monitor monitor(9600); // to visualize the results of both Chronometer objects
Metronome monitorMetro (1.0); //to make reading the values easier
int lap = 1; // value for storing which lap we are on
void begin() {
pauseButton.debounce();
lapButton.debounce();
mainChrono.start();
lapChrono.start();
}
void step() {
if (pauseButton.rose()) {
print ("System is Paused at ");
println (mainChrono);
mainChrono.pause(); // stop the Chronometer while preserving the last value
lapChrono.pause();
}
if (pauseButton.fell()) {
print ("System is Resumed at ");
println (mainChrono);
mainChrono.resume(); // continue the Chronometer from last value
lapChrono.resume();
}
if (lapButton.rose()) {
print ("Lap ");
print (lap);
print (": ");
println (lapChrono);
lap++;
lapChrono.stop(); // Stop the Chronometer and set to 0.0
}
if(lapButton.fell()) {
lapChrono.resume(); // restart the lap Chronometer
println ("New lap commenced.");
}
if(mainChrono.isRunning())
sine >> runningLed; // pulse a sine wave to the led
else 0 >> runningLed; // clear the last value to the led and send a 0 to turn it off.
if (monitorMetro) {
if (!mainChrono.isRunning()) {
print ("System is Paused at ");
println (mainChrono);
}
else {
print ("mainChrono: ");
println (mainChrono);
}
}
}
Lap Button
Pause Button