-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelayModule.h
More file actions
131 lines (108 loc) · 2.28 KB
/
RelayModule.h
File metadata and controls
131 lines (108 loc) · 2.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
RelayModule.h - The interface describes a set of methods
for working with a digital relay module.
Instantiation:
RelayModule relay(2);
If you need to invert a sensor signal:
RelayModule relay(2, true);
or call the method:
relay.invert();
Methods:
relay.on();
relay.off();
relay.isOn();
relay.isOff();
https://github.com/YuriiSalimov/RelayModule
Created by Yurii Salimov, February, 2018.
Released into the public domain.
*/
#ifndef RELAY_MODULE_H
#define RELAY_MODULE_H
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
class RelayModule final {
private:
/**
Port number that is attached to the relay.
*/
int IN_pin = 0;
/**
ON and OFF signal.
*/
volatile int onSignal = LOW;
volatile int offSignal = HIGH;
public:
/**
Constructor.
@param IN_pin - a digital port number
that is attached to the relay.
*/
RelayModule(const int IN_pin);
/**
Constructor.
@param IN_pin - a digital port number
that is attached to the relay.
@param invertSignal - invert relay signal:
true - LOW is a ON signal;
false - HIGH is a ON signal.
*/
RelayModule(const int IN_pin, const boolean invertSignal);
~RelayModule();
/**
Turns on the relay if it is off.
*/
void on();
/**
Turns off the relay if it is on.
*/
void off();
/**
Checks if the relay is on.
@return true if the relay is on,
false if the relay is off.
*/
boolean isOn();
/**
Checks if the relay is off.
@return true if the relay is off,
false if the relay is on.
*/
boolean isOff();
/**
Inverts relay signal.
If invert signal:
onSignal = LOW
offSignal = HIGH
If not invert signal:
onSignal = HIGH
offSignal = LOW
*/
void invert();
private:
/**
Initialization of module.
*/
void init();
/**
Turns on the relay.
*/
void turnOn();
/**
Turns off the relay.
*/
void turnOff();
/**
Wrintes a input signal to the relay.
@param value - a new relay signal.
*/
void write(const int signal);
/**
Reads and returns the relay signal.
@return relay signal.
*/
int read();
};
#endif