forked from manojkoushik/ObservatoryPowerControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTapasObsPower.ino
More file actions
93 lines (78 loc) · 2.53 KB
/
TapasObsPower.ino
File metadata and controls
93 lines (78 loc) · 2.53 KB
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
#include <NCD4Relay.h>
#include <neopixel.h>
NCD4Relay relayController;
Adafruit_NeoPixel neoPixels(83, D5, WS2812B);
SYSTEM_MODE(AUTOMATIC);
int triggerRelay(String command);
int Dome = 1;
int MM200 = 2;
int Scopes = 3;
int Weather = 4;
/* This function is called once at start up ----------------------------------*/
void setup()
{
Particle.function("ObsPower", triggerRelay);
Particle.function("ObsLight", light);
relayController.setAddress(0,0,0);
RGB.control(true);
RGB.brightness(0);
pinMode(D5, OUTPUT);
neoPixels.begin();
}
/* This function loops forever --------------------------------------------*/
void loop()
{
}
int light(String command) {
int r = command.substring(0,command.indexOf(':')).toInt();
command = command.substring(command.indexOf(':')+1);
int g = command.substring(0,command.indexOf(':')).toInt();
command = command.substring(command.indexOf(':')+1);
int b = command.substring(0,command.indexOf(':')).toInt();
command = command.substring(command.indexOf(':')+1);
int brightness = command.substring(0,command.indexOf(':')).toInt();
uint16_t i;
for(i=0; i<neoPixels.numPixels(); i++) {
neoPixels.setPixelColor(i, neoPixels.Color(r, g, b));
}
neoPixels.setBrightness(brightness);
neoPixels.show();
}
int triggerRelay(String fullCommand){
String equipment = fullCommand.substring(0,fullCommand.indexOf(':'));
String command = fullCommand.substring(fullCommand.indexOf(':')+1);
if(equipment.equalsIgnoreCase("All")) {
triggerRelay("Dome:"+command);
triggerRelay("MM200:"+command);
triggerRelay("Scopes:"+command);
triggerRelay("Weather:"+command);
return 1;
}
//Relay Specific Command
int relayNumber;
String equip;
if(equipment.equalsIgnoreCase("Dome")) {
relayNumber = Dome;
equip = "Dome";
} else if(equipment.equalsIgnoreCase("MM200")) {
relayNumber = MM200;
equip = "MM200";
} else if(equipment.equalsIgnoreCase("Scopes")) {
relayNumber = Scopes;
equip = "Scopes";
} else if(equipment.equalsIgnoreCase("Weather")) {
relayNumber = Weather;
equip = "Weather";
}
if(command.equalsIgnoreCase("On")){
relayController.turnOnRelay(relayNumber);
Particle.publish(equip, "On", 16777215);
return 1;
}
if(command.equalsIgnoreCase("Off")){
relayController.turnOffRelay(relayNumber);
Particle.publish(equip, "Off", 16777215);
return 1;
}
return 0;
}