-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ino
92 lines (77 loc) · 1.76 KB
/
main.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
#include <RCSwitch.h>
typedef unsigned long int Code;
// Switches
RCSwitch receiveSwitch = RCSwitch();
RCSwitch transmitSwitch = RCSwitch();
// Pins
const int RECEIVER_INTERRUPT = 0;
const int TRANSMITTER_PIN = 10;
const int BIT_LENGTH = 24;
const int LED_PIN = 13; // Onboard LED pin
// Key Codes
Code MASTER_UP_CODE = 6532833;
Code MASTER_DOWN_CODE = 6532834;
const long CODE_WAIT_TIME = 500;
const int codeNum = 12;
// Up codes for each desk (1-12)
// Down code = Up code + 1
Code codes[] = {
6532833,
13806609,
10427409,
15956497,
78353,
13108961,
473617,
6525457,
252945,
9861857,
14031377,
711697,
};
// Prototypes
void sendCode(Code code);
void raiseAll();
void lowerAll();
void setup() {
Serial.begin(9600);
receiveSwitch.enableReceive(RECEIVER_INTERRUPT);
transmitSwitch.enableTransmit(TRANSMITTER_PIN);
pinMode(LED_PIN, OUTPUT); // Set up on-board LED pin
Serial.println("Setup complete");
Serial.println("Listening...");
}
void loop() {
if (receiveSwitch.available()) {
Code value = receiveSwitch.getReceivedValue();
if (value == MASTER_UP_CODE) {
raiseAll();
} else if (value == MASTER_DOWN_CODE) {
lowerAll();
}
receiveSwitch.resetAvailable();
}
}
void sendCode(Code code) {
Serial.print("sending");
Serial.println(code);
transmitSwitch.send(code, BIT_LENGTH);
}
void raiseAll() {
Serial.println("Transmitting up codes");
for (int i = 0; i < codeNum; i++) {
Code code = codes[i];
sendCode(code);
delay(CODE_WAIT_TIME);
}
Serial.println("Done. \nListening...");
}
void lowerAll() {
Serial.println("Transmitting down codes");
for (int i = 0; i < codeNum; i++) {
Code code = codes[i] + 1;
sendCode(code);
delay(CODE_WAIT_TIME);
}
Serial.println("Done. \nListening...");
}