-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempurpedic-remote-relay.ino
59 lines (47 loc) · 1.84 KB
/
tempurpedic-remote-relay.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
// This #include statement was automatically added by the Particle IDE.
#include "NCD16Relay/NCD16Relay.h"
NCD16Relay relayController;
int turnOnRelay(String command);
int turnOffRelay(String command);
void setup() {
// Set up the Relays
relayController.setAddress(0, 0, 0);
relayController.turnOffAllRelays();
// register the cloud functions
Particle.function("turnOnRelay", turnOnRelay);
Particle.function("turnOffRelay", turnOffRelay);
}
void loop() {
}
/*******************************************************************************
* Function Name : turnOnRelay
* Description : Turns the specified relay on
* Input : Relay Number (1-16)
* Output : None.
* Return : 1 on success and a negative number on failure
*******************************************************************************/
int turnOnRelay(String command) {
// Convert command to int
int relayNumber = command.toInt();
// Sanity check to see if the relay number is within limits
if (relayNumber< 1 || relayNumber >16) return -1;
// Turn on the relay
relayController.turnOnRelay(relayNumber);
return 1;
}
/*******************************************************************************
* Function Name : turnOffRelay
* Description : Turns the specified relay off
* Input : Relay Number (1-16)
* Output : None.
* Return : 1 on success and a negative number on failure
*******************************************************************************/
int turnOffRelay(String command) {
// Convert command to int
int relayNumber = command.toInt();
// Sanity check to see if the relay number is within limits
if (relayNumber< 1 || relayNumber >16) return -1;
// Turn on the relay
relayController.turnOffRelay(relayNumber);
return 1;
}