upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the Relay. More...

Detailed Description

UPM module for the relay switch. The relay is a digital normally-open switch that uses low voltage or current to control a higher voltage and/or higher current. When closed, the indicator LED (if present) lights up and current is allowed to flow.

relay.jpg
// Create the relay switch object using GPIO pin 0
upm::Relay relay(0);
// Close and then open the relay switch 3 times,
// waiting one second each time. The LED on the relay switch
// will light up when the switch is on (closed).
// The switch will also make a noise between transitions.
for (int i = 0; i < 3; i++) {
relay.on();
if (relay.isOn())
std::cout << relay.name() << " is on" << std::endl;
upm_delay(1);
relay.off();
if (relay.isOff())
std::cout << relay.name() << " is off" << std::endl;
upm_delay(1);
}
// Delete the relay switch object

Public Member Functions

 Relay (unsigned int pin)
 
 ~Relay ()
 
mraa_result_t on ()
 
mraa_result_t off ()
 
bool isOn ()
 
bool isOff ()
 
std::string name ()
 

Constructor & Destructor Documentation

Relay ( unsigned int  pin)

relay constructor

Parameters
pinPin to use
~Relay ( )

relay destructor

Member Function Documentation

mraa_result_t on ( )

Sets the relay switch to on (closed). This allows current to flow and lights up the indicator LED.

Returns
0 if successful, non-zero otherwise
mraa_result_t off ( )

Sets the relay switch to off (open). This stops current from flowing and the indicator LED is not lit.

Returns
0 if successful, non-zero otherwise
bool isOn ( )

Defines whether the relay switch is closed.

Returns
True if the switch is on (closed), false otherwise
bool isOff ( )

Defines whether the relay switch is open.

Returns
True if the switch is off (open), false otherwise

The documentation for this class was generated from the following files: