Completing firmware for the temperature/humidity, IR, and magnetic sensors for both...
[iotcloud.git] / version2 / src / others / RPi / LightsController.ino
1 // ------------------------------------------------
2 // Controlling LifxLightBulb through Particle Cloud
3 // @author Rahmadi Trimananda - UC Irvine
4 // ------------------------------------------------
5
6 #include "LifxLightBulb.h"
7
8 LifxLightBulb *llb1;
9 LifxLightBulb *llb2;
10
11 int led1 = D7;
12
13 void setup()
14 {
15         // Bulb 1
16         char macAddress1[8];
17         macAddress1[0] = 0xD0;
18         macAddress1[1] = 0x73;
19         macAddress1[2] = 0xD5;
20         macAddress1[3] = 0x12;
21         macAddress1[4] = 0x8E;
22         macAddress1[5] = 0x30;
23         macAddress1[6] = 0x00; 
24         macAddress1[7] = 0x00;
25         IPAddress devIPAddress1(192, 168, 1, 126);
26
27         llb1 = new LifxLightBulb(devIPAddress1, macAddress1, 12345);
28         llb1->init();
29         
30         // Bulb 2
31         char macAddress2[8];
32         macAddress2[0] = 0xD0;
33         macAddress2[1] = 0x73;
34         macAddress2[2] = 0xD5;
35         macAddress2[3] = 0x02;
36         macAddress2[4] = 0x41;
37         macAddress2[5] = 0xDA;
38         macAddress2[6] = 0x00; 
39         macAddress2[7] = 0x00;
40         IPAddress devIPAddress2(192, 168, 1, 232);
41
42         llb2 = new LifxLightBulb(devIPAddress2, macAddress2, 12346);
43         llb2->init();
44
45         pinMode(led1, OUTPUT);
46         // Argument needed ("on" or "off") for these functions
47     //Particle.function("lifx1",lifxb1Toggle);
48     //Particle.function("lifx2",lifxb2Toggle);
49
50     // Argument not needed for these functions
51     Particle.function("turnOn_1",turnOnLiFX_1);
52     Particle.function("turnOff_1",turnOffLiFX_1);
53     Particle.function("turnOn_2",turnOnLiFX_2);
54     Particle.function("turnOff_2",turnOffLiFX_2);
55 }
56
57
58 void loop() {
59     // Nothing to do here
60 }
61
62
63 // Toggling Lifx light bulb 1
64 int lifx1Toggle(String command) {
65
66     if (command=="on") {
67         llb1->turnOn();
68         return 1;
69     }
70     else if (command=="off") {
71         llb1->turnOff();
72         return 0;
73     }
74     else {
75         return -1;
76     }
77 }
78
79 // Toggling Lifx light bulb 2
80 int lifx2Toggle(String command) {
81
82     if (command=="on") {
83         llb2->turnOn();
84         return 1;
85     }
86     else if (command=="off") {
87         llb2->turnOff();
88         return 0;
89     }
90     else {
91         return -1;
92     }
93 }
94
95
96 int turnOnLiFX_1(String command) {
97
98         llb1->turnOn();
99         return 1;
100 }
101
102
103 int turnOffLiFX_1(String command) {
104
105         llb1->turnOff();
106         return 1;
107 }
108
109
110 int turnOnLiFX_2(String command) {
111
112         llb2->turnOn();
113         return 1;
114 }
115
116
117 int turnOffLiFX_2(String command) {
118
119         llb2->turnOff();
120         return 1;
121 }
122