-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle-source-code
66 lines (49 loc) · 1.09 KB
/
particle-source-code
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
// declaring physical connections
int fanPin = D2;
int pumpPin = D5;
// functions to be used
int controller(String command);
void fanOn();
void fanOff();
void pumpOn();
void pumpOff();
void setup() {
pinMode(fanPin, OUTPUT);
pinMode(pumpPin, OUTPUT);
digitalWrite(fanPin, LOW);
digitalWrite(pumpPin, LOW);
Particle.function("controller", controller);
}
void loop() {
}
int controller(String command) {
if(command == "fan on") {
fanOn();
}
if(command == "fan off") {
fanOff();
}
if(command == "pump on") {
pumpOn();
}
if(command == "pump off") {
pumpOff();
}
return 0;
}
void fanOn() {
digitalWrite(fanPin, HIGH);
Particle.publish("fanWebHook", "1", PRIVATE);
}
void fanOff() {
digitalWrite(fanPin, LOW);
Particle.publish("fanWebHook", "0", PRIVATE);
}
void pumpOn() {
digitalWrite(pumpPin, HIGH);
Particle.publish("pumpWebHook", "1", PRIVATE);
}
void pumpOff() {
digitalWrite(pumpPin, LOW);
Particle.publish("pumpWebHook", "0", PRIVATE);
}