upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
Relay Class Reference

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 = new upm::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;
sleep(1);
relay->off();
if ( relay->isOff() )
std::cout << relay->name() << " is off" << std::endl;
sleep(1);
}
// Delete the relay switch object
delete relay;

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: