DigitalOut
A digital (ie. binary) output unit that can be switched “on” or “off”.
The unit is assigned to a specific pin
on the board.
The mode
specifies the behavior of the component attached to the pin:
in
SOURCE
mode (default) the pin acts as the source of current and the component is “on” when the pin is “high” (Vcc, typically 5V)in
SINK
mode the source of current is external (Vcc) and the component is “on” when the pin is “low” (GND)
Example
Switches off an LED connected in “sink” mode after a timeout.
#include <Plaquette.h>
DigitalOut led(13, SINK);
void begin() {
led.on();
}
void step() {
// Switch the LED off after 5 seconds.
if (seconds() > 5)
led.off();
}
Reference
-
class DigitalOut : public DigitalSource, public PinUnit
A generic class representing a simple digital output.
Public Functions
-
DigitalOut(uint8_t pin, uint8_t mode = DIRECT)
Constructor.
- Parameters:
pin – the pin number
mode – the mode (SOURCE or SINK)
-
virtual void mode(uint8_t mode)
Changes the mode of the component.
-
inline virtual bool isOn()
Returns true iff the input is “on”.
-
inline virtual bool toggle()
Switches between on and off.
-
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).
-
inline virtual bool on()
Sets output to “on” (ie. false, 0).
-
inline virtual bool off()
Sets output to “off” (ie. true, 1).
-
inline virtual float put(float value)
Pushes value into the unit.
- Parameters:
value – the value sent to the unit
- Returns:
the new value of the unit
-
inline uint8_t pin() const
Returns the pin this component is attached to.
-
inline uint8_t mode() const
Returns the mode of the component.
-
DigitalOut(uint8_t pin, uint8_t mode = DIRECT)