Initial version of Lifx lightbulb controller in C++ for Fidelius
[iotcloud.git] / version2 / src / 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 void setup()
12 {
13         // Bulb 1
14         string macAddress1 = "D073D5128E300000";
15         uint8_t devIPAddress1[] = { 192, 168, 1, 126 };
16         llb1 = new LifxLightBulb(devIPAddress1, macAddress1, 12345);
17         llb1->init();
18         
19         // Bulb 2
20         string macAddress2 = "D073D50241DA0000";
21         uint8_t devIPAddress2[] = { 192, 168, 1, 232 };
22         llb2 = new LifxLightBulb(devIPAddress2, macAddress2, 12346);
23         llb2->init();
24         
25     Particle.function("lifx1",lifx1Toggle);
26     Particle.function("lifx2",lifx2Toggle);
27 }
28
29
30 void loop()
31 {
32     // Nothing to do here
33         for(int i=0; i < 3; i++) {
34                 llb1->turnOff();
35                 delay(1000);
36                 llb1->turnOn();
37                 delay(1000);
38         }
39 }
40
41
42 // Toggling Lifx light bulb 1
43 int lifx1Toggle(String command) {
44
45     if (command=="on") {
46         llb1->turnOn();
47         return 1;
48     }
49     else if (command=="off") {
50         llb1->turnOff();
51         return 0;
52     }
53     else {
54         return -1;
55     }
56 }
57
58 // Toggling Lifx light bulb 2
59 int lifx2Toggle(String command) {
60
61     if (command=="on") {
62         llb2->turnOn();
63         return 1;
64     }
65     else if (command=="off") {
66         llb2->turnOff();
67         return 0;
68     }
69     else {
70         return -1;
71     }
72 }