Chronometer
An analog unit that counts time in seconds. It can be started, stopped, paused, and resumed.
Example
Uses a chronometer to change the frequency a blinking LED. Restarts after 10 seconds.
#include <Plaquette.h>
Chronometer chrono;
DigitalOut led(13);
SquareOsc osc(1.0); // a square oscillator
void begin() {
chrono.start(); // start chrono
}
void step() {
// Adjust oscillator's duty cycle according to current timer progress.
osc.frequency(chrono);
// Apply oscillator to LED state.
osc >> led;
// If the chronometer reaches 10 seconds: restart it.
if (chrono >= 10.0)
{
// Restarts the chronometer.
chrono.start();
}
}
Reference
-
class Chronometer : public Unit, public AbstractChronometer
Public Functions
-
Chronometer()
Constructor.
-
inline virtual float get()
Returns elapsed time since start (in seconds).
-
virtual void start()
Starts/restarts the chronometer.
-
virtual void stop()
Interrupts the chronometer and resets to zero.
-
virtual void pause()
Interrupts the chronometer.
-
virtual void resume()
Resumes process.
-
inline virtual float elapsed() const
The time currently elapsed by the chronometer (in seconds).
-
virtual void set(float time)
Forces current time (in seconds).
-
virtual void add(float time)
Adds/subtracts time to the chronometer.
-
inline bool isRunning() const
Returns true iff the chronometer is currently running.
-
Chronometer()