-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelay-lib.cpp
More file actions
81 lines (68 loc) · 1.28 KB
/
relay-lib.cpp
File metadata and controls
81 lines (68 loc) · 1.28 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "relay-lib.h"
//
// The constructor sets up a single relay, specified by the Pin that relay is attached to
//
// The constructor will also properly set the assigned pin to OUTPUT.
//
RelayLib::RelayLib(int _relayPin, int _state)
{
relayPin=_relayPin;
pinMode(relayPin, OUTPUT);
if (_state == LOW) {
relayState=LOW;
off();
}
else {
relayState=HIGH;
on();
}
}
//Set up with default to LOW
RelayLib::RelayLib(int _relayPin)
{
relayPin=_relayPin;
pinMode(relayPin, OUTPUT);
relayState=LOW;
}
// Turns the relay on.
void RelayLib::on()
{
digitalWrite(relayPin, HIGH);
relayState=HIGH;
}
// Turns the relay off.
void RelayLib::off()
{
digitalWrite(relayPin, LOW);
relayState=LOW;
}
//Toggles the state of the relay
void RelayLib::toggle()
{
if (relayState==HIGH) {
off();
} else {
on();
}
}
// Returns the state of the relay (LOW/0 or HIGH/1)
int RelayLib::state()
{
return(relayState);
}
// If the relay is on, returns true, otherwise returns false
int RelayLib::isRelayOn()
{
if (relayState==HIGH)
return true;
else
return false;
}
// If the relay is off, returns true, otherwise returns false
int RelayLib::isRelayOff()
{
if (relayState==LOW)
return true;
else
return false;
}