-
Notifications
You must be signed in to change notification settings - Fork 0
/
8relay.ino
238 lines (229 loc) · 6.63 KB
/
8relay.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// Simple sketch to interface to the 'Relais Interface Grundgerät'
// (http://www.ak-modul-bus.de/stat/relais_interface_grundgeraet,pd10!0,,RIST.html)
// The atmega328 is wired directly to the 20 pin DIP socket of the
// original microcontroller (AT90S1200).
//
// This sketch uses an Ciseco XRF to transmit/receive data wirelessly, it relies
// on the Ciseco LLAPSerial library - https://github.com/CisecoPlc/LLAPSerial
//
// Functions supported:
//
// * aR8RELAY#ON- (turn relay # on)
// * aR8RELAY#OFF (turn relay # off)
// * aR8RELAY#TOG (toggle state of relay #)
// * aR8RELAYAON- (turn on all relays)
// * aR8RELAYAOFF (turn off all relays)
//
// Pinout of AT90S1200 socket
//
// +-\/-+
// NC 1| |20 Vcc / Vin
// NC 2| |19 Arduino Pin 2
// NC 3| |18 Arduino Pin 3
// NC 4| |17 Arduino Pin 4
// NC 5| |16 Arduino Pin 5
// NC 6| |15 Arduino Pin 6
// NC 7| |14 Arduino Pin 7
// NC 8| |13 Arduino Pin 8
// NC 9| |12 Arduino Pin 9
// GND 10| |11 NC
// +----+
//
//
// Ben Morrice July 2016
#include "LLAPSerial.h"
#define DEVICEID "R8"
#define Relay1 2
#define Relay2 3
#define Relay3 4
#define Relay4 5
#define Relay5 6
#define Relay6 7
#define Relay7 8
#define Relay8 9
int tmp;
void setup() {
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
pinMode(Relay8, OUTPUT);
Serial.begin(9600);
LLAP.init(DEVICEID);
LLAP.sendMessage(String("STARTED"));
}
void loop() {
if (LLAP.bMsgReceived) {
if (LLAP.sMessage.equals("RELAY1ON-")) {
digitalWrite(Relay1,HIGH);
LLAP.sendMessage(String("RELAY1ON"));
}
if (LLAP.sMessage.equals("RELAY1OFF")) {
digitalWrite(Relay1,LOW);
LLAP.sendMessage(String("RELAY1OFF"));
}
if (LLAP.sMessage.equals("RELAY2ON-")) {
digitalWrite(Relay2,HIGH);
LLAP.sendMessage(String("RELAY2ON"));
}
if (LLAP.sMessage.equals("RELAY2OFF")) {
digitalWrite(Relay2,LOW);
LLAP.sendMessage(String("RELAY2OFF"));
}
if (LLAP.sMessage.equals("RELAY3ON-")) {
digitalWrite(Relay3,HIGH);
LLAP.sendMessage(String("RELAY3ON"));
}
if (LLAP.sMessage.equals("RELAY3OFF")) {
digitalWrite(Relay3,LOW);
LLAP.sendMessage(String("RELAY3OFF"));
}
if (LLAP.sMessage.equals("RELAY4ON-")) {
digitalWrite(Relay4,HIGH);
LLAP.sendMessage(String("RELAY4ON"));
}
if (LLAP.sMessage.equals("RELAY4OFF")) {
digitalWrite(Relay4,LOW);
LLAP.sendMessage(String("RELAY4OFF"));
}
if (LLAP.sMessage.equals("RELAY5ON-")) {
digitalWrite(Relay5,HIGH);
LLAP.sendMessage(String("RELAY5ON"));
}
if (LLAP.sMessage.equals("RELAY5OFF")) {
digitalWrite(Relay5,LOW);
LLAP.sendMessage(String("RELAY5OFF"));
}
if (LLAP.sMessage.equals("RELAY6ON-")) {
digitalWrite(Relay6,HIGH);
LLAP.sendMessage(String("RELAY6ON"));
}
if (LLAP.sMessage.equals("RELAY6OFF")) {
digitalWrite(Relay6,LOW);
LLAP.sendMessage(String("RELAY6OFF"));
}
if (LLAP.sMessage.equals("RELAY7ON-")) {
digitalWrite(Relay7,HIGH);
LLAP.sendMessage(String("RELAY7ON"));
}
if (LLAP.sMessage.equals("RELAY7OFF")) {
digitalWrite(Relay7,LOW);
LLAP.sendMessage(String("RELAY7OFF"));
}
if (LLAP.sMessage.equals("RELAY8ON-")) {
digitalWrite(Relay8,HIGH);
LLAP.sendMessage(String("RELAY8ON"));
}
if (LLAP.sMessage.equals("RELAY8OFF")) {
digitalWrite(Relay8,LOW);
LLAP.sendMessage(String("RELAY8OFF"));
}
if (LLAP.sMessage.equals("RELAY1TOG")) {
tmp = digitalRead(Relay1);
if (tmp == 1) {
digitalWrite(Relay1,LOW);
LLAP.sendMessage(String("RELAY1OFF"));
} else {
digitalWrite(Relay1,HIGH);
LLAP.sendMessage(String("RELAY1ON"));
}
}
if (LLAP.sMessage.equals("RELAY2TOG")) {
tmp = digitalRead(Relay2);
if (tmp == 1) {
digitalWrite(Relay2,LOW);
LLAP.sendMessage(String("RELAY2OFF"));
} else {
digitalWrite(Relay2,HIGH);
LLAP.sendMessage(String("RELAY2ON"));
}
}
if (LLAP.sMessage.equals("RELAY3TOG")) {
tmp = digitalRead(Relay3);
if (tmp == 1) {
digitalWrite(Relay3,LOW);
LLAP.sendMessage(String("RELAY3OFF"));
} else {
digitalWrite(Relay3,HIGH);
LLAP.sendMessage(String("RELAY3ON"));
}
}
if (LLAP.sMessage.equals("RELAY4TOG")) {
tmp = digitalRead(Relay4);
if (tmp == 1) {
digitalWrite(Relay4,LOW);
LLAP.sendMessage(String("RELAY4OFF"));
} else {
digitalWrite(Relay4,HIGH);
LLAP.sendMessage(String("RELAY4ON"));
}
}
if (LLAP.sMessage.equals("RELAY5TOG")) {
tmp = digitalRead(Relay5);
if (tmp == 1) {
digitalWrite(Relay5,LOW);
LLAP.sendMessage(String("RELAY5OFF"));
} else {
digitalWrite(Relay5,HIGH);
LLAP.sendMessage(String("RELAY5ON"));
}
}
if (LLAP.sMessage.equals("RELAY6TOG")) {
tmp = digitalRead(Relay6);
if (tmp == 1) {
digitalWrite(Relay6,LOW);
LLAP.sendMessage(String("RELAY6OFF"));
} else {
digitalWrite(Relay6,HIGH);
LLAP.sendMessage(String("RELAY6ON"));
}
}
if (LLAP.sMessage.equals("RELAY7TOG")) {
tmp = digitalRead(Relay7);
if (tmp == 1) {
digitalWrite(Relay7,LOW);
LLAP.sendMessage(String("RELAY7OFF"));
} else {
digitalWrite(Relay7,HIGH);
LLAP.sendMessage(String("RELAY7ON"));
}
}
if (LLAP.sMessage.equals("RELAY8TOG")) {
tmp = digitalRead(Relay8);
if (tmp == 1) {
digitalWrite(Relay8,LOW);
LLAP.sendMessage(String("RELAY8OFF"));
} else {
digitalWrite(Relay8,HIGH);
LLAP.sendMessage(String("RELAY8ON"));
}
}
if (LLAP.sMessage.equals("RELAYAON0")) {
digitalWrite(Relay1,HIGH);
digitalWrite(Relay2,HIGH);
digitalWrite(Relay3,HIGH);
digitalWrite(Relay4,HIGH);
digitalWrite(Relay5,HIGH);
digitalWrite(Relay6,HIGH);
digitalWrite(Relay7,HIGH);
digitalWrite(Relay8,HIGH);
LLAP.sendMessage(String("RELAYAON"));
}
if (LLAP.sMessage.equals("RELAYAOFF")) {
digitalWrite(Relay1,LOW);
digitalWrite(Relay2,LOW);
digitalWrite(Relay3,LOW);
digitalWrite(Relay4,LOW);
digitalWrite(Relay5,LOW);
digitalWrite(Relay6,LOW);
digitalWrite(Relay7,LOW);
digitalWrite(Relay8,LOW);
LLAP.sendMessage(String("RELAYAOFF"));
}
LLAP.bMsgReceived = false;
} // end message received
} //end loop