b47d15d2cf69daa30085192edbd214fda8333cd6
[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     Particle.function("lifx1",lifx1Toggle);
47     Particle.function("lifx2",lifx2Toggle);
48 }
49
50
51 void loop() {
52     // Nothing to do here
53 }
54
55
56 // Toggling Lifx light bulb 1
57 int lifx1Toggle(String command) {
58
59     if (command=="on") {
60         llb1->turnOn();
61         return 1;
62     }
63     else if (command=="off") {
64         llb1->turnOff();
65         return 0;
66     }
67     else {
68         return -1;
69     }
70 }
71
72 // Toggling Lifx light bulb 2
73 int lifx2Toggle(String command) {
74
75     if (command=="on") {
76         llb2->turnOn();
77         return 1;
78     }
79     else if (command=="off") {
80         llb2->turnOff();
81         return 0;
82     }
83     else {
84         return -1;
85     }
86 }