-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelay.cpp
68 lines (56 loc) · 1.27 KB
/
Relay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Relay.hpp"
// Get/Set
//------------------------------------------------------------------------------
// GPIO
int Relay::GetGPIO(){
return this->GPIO;
}
// Status
int Relay::GetStatus(){
int pin = this->GPIO;
return digitalRead(pin);
}
bool Relay::GetTriggerLow(){
return this->TriggerLow;
}
void Relay::SetGPIO(int gpio){
this->GPIO = gpio;
pinMode(this->GPIO, OUTPUT);
}
void Relay::SetStatus(){
this->Status = Relay::GetGPIO();
}
// Methods
//------------------------------------------------------------------------------
void Relay::Switch(){
int pin = this->GetGPIO();
if (this->GetStatus() == 0) {
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
}
this->SetStatus();
}
// Constructor
//------------------------------------------------------------------------------
Relay::Relay(int gpio){
this->SetGPIO(gpio);
digitalWrite(gpio, LOW);
}
Relay::Relay(int gpio, bool enable = "false", bool trigger_low = "false"){
this->SetGPIO(gpio);
if (enable == true){
if (trigger_low == true) {
digitalWrite(gpio, LOW);
} else {
digitalWrite(gpio, HIGH);
}
} else {
if (trigger_low == true) {
digitalWrite(gpio, HIGH);
} else {
digitalWrite(gpio, LOW);
}
}
this->SetStatus();
}