SimpleRelay
All Classes Files Functions Pages
SimpleRelay.cpp
Go to the documentation of this file.
1
23#include "SimpleRelay.h"
24
32SimpleRelay::SimpleRelay(uint8_t pin, bool isInverted) {
33 m_pin = pin;
34 m_relayOnLogicLevel = isInverted ? LOW : HIGH;
35 pinMode(m_pin, OUTPUT);
36 off();
37}
38
43 // set pin to high impedance
44 pinMode(m_pin, INPUT);
45}
46
50void SimpleRelay::on(void) {
51 m_state = State::RELAY_ON;
52 digitalWrite(m_pin, m_relayOnLogicLevel);
53}
54
58void SimpleRelay::off(void) {
59 m_state = State::RELAY_OFF;
60 digitalWrite(m_pin, m_relayOnLogicLevel == HIGH ? LOW : HIGH);
61}
62
67 if (m_state == State::RELAY_ON) {
68 off();
69 } else {
70 on();
71 }
72}
73
79 return m_state == State::RELAY_ON;
80}
Relay library for Arduino.
~SimpleRelay()
Destructor for the class.
bool isRelayOn(void)
Get information if a relay is currently ON.
void off(void)
Set relay to OFF state.
void on(void)
Set relay to ON state.
void toggle(void)
Toggle relay state.
SimpleRelay(uint8_t pin, bool isInverted=false)
Constructor for the class.