Alarm

An alarm clock digital source unit. Counts time and becomes “on” when time is up. The alarm can be started, stopped, and resumed.

When started, the alarm stays “off” until it reaches its timeout duration, after which it becomes “on”.

Example

Uses an alarm to activate built-in LED. Button is used to reset the alarm at random periods of time.

#include <Plaquette.h>

Alarm myAlarm(2.0); // an alarm with 2 seconds duration

DigitalOut led(13);

DigitalIn button(2, INTERNAL_PULLUP);

void begin() {
  myAlarm.start(); // start alarm
}

void step() {
  // Activate LED when alarm rings.
  myAlarm >> led; // the alarm will stay "on" until it is stopped or restarted

  // Reset alarm when button is pushed.
  if (myAlarm && button.rose())
  {
    // Restarts the alarm with a random duration between 1 and 5 seconds.
    myAlarm.duration(randomFloat(1.0, 5.0));
    myAlarm.start();
  }
}

Reference

class Alarm : public DigitalNode, public AbstractTimer

Chronometer class which becomes “on” after a given duration.

Public Functions

virtual bool isOn()

True when time is up.

inline virtual bool isOff()

Returns true iff the input is “off”.

inline virtual int getInt()

Returns value as integer (0 or 1).

inline virtual float get()

Returns value as float (either 0.0 or 1.0).

virtual void start()

Starts/restarts the chronometer.

virtual void start(float duration)

Starts/restarts the chronometer with specific duration.

virtual float progress() const

The progress of the timer process (in %).

virtual void stop()

Interrupts the chronometer.

virtual void resume()

Resumes process.

inline virtual float elapsed() const

The time currently elapsed by the chronometer (in seconds).

inline bool isStarted() const

Returns true iff the chronometer is currently running.

See Also