-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelay.cpp
More file actions
55 lines (43 loc) · 1.01 KB
/
Copy pathrelay.cpp
File metadata and controls
55 lines (43 loc) · 1.01 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
// **********************************************************************************
// ESP8266 / ESP32 Digital Relay
// **********************************************************************************
//
// History : V1.00 2025-03-13 - First release
//
// **********************************************************************************
#include "relay.h"
DigitalRelay::DigitalRelay() {
}
/*
* pin : gpio pin number
* inverted : true or false
* true : gpio LOW ; Relay Activated
* false : gpio HIGH : Relay Activated
*/
void DigitalRelay::begin( int pin, bool inverted)
{
_pin = pin;
_inverted = inverted;
pinMode(_pin, OUTPUT);
Off();
}
/*
* Relay On
*/
void DigitalRelay::On()
{
if (_inverted)
digitalWrite(_pin, LOW); // Active LOW relay
else
digitalWrite(_pin, HIGH); // Active HIGHT relay
}
/*
* Relay Off
*/
void DigitalRelay::Off()
{
if (_inverted)
digitalWrite(_pin, HIGH); // Active LOW relay
else
digitalWrite(_pin, LOW); // Active HIGHT relay
}