-
Notifications
You must be signed in to change notification settings - Fork 0
/
relay_control.ino
57 lines (47 loc) · 1 KB
/
relay_control.ino
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
#define DEBUG 1
#define RELAY_PIN 12
#define DEBUG_PIN 13
void setup() {
// put your setup code here, to run once:
// Optional debug pin, just to show a light
// when we have power to the relay
if (DEBUG)
{
// initialize digital pin 13 as an output
pinMode(DEBUG_PIN, OUTPUT);
}
// initialize relay pin as an output
pinMode(RELAY_PIN, OUTPUT);
// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop() {
// put your main code here, to run repeatedly:
int inByte = 0; // incoming serial byte
// Read data off serial
if (Serial.available() > 0)
{
// get incoming byte:
inByte = Serial.read();
if (inByte == '0')
{
send_signal(LOW);
}
else if (inByte == '1')
{
send_signal(HIGH);
}
}
}
void send_signal(int voltage)
{
if (DEBUG)
{
digitalWrite(DEBUG_PIN, voltage);
}
digitalWrite(RELAY_PIN, voltage);
}