Skip to content

Commit c693d99

Browse files
committed
Update DuinoLightProp.ino
1 parent 4065dcd commit c693d99

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

room-software/Tutorial - Audio and light effects/Part-2/DuinoLightProp/DuinoLightProp.ino

+36-29
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Set SECRET_SSID and SECRET_PASS in arduino_secrets.h
55
6-
Requirements:
6+
Requirements:
77
- install ArduinoProps.zip library and dependencies (https://github.com/fauresystems/ArduinoProps)
88
- help: https://github.com/xcape-io/ArduinoProps/blob/master/help/ArduinoProps_sketch.md
99
*/
@@ -15,10 +15,10 @@ char ssid[] = SECRET_SSID; // your network SSID (name)
1515
char pass[] = SECRET_PASS; // your network password (use for WPA)
1616

1717
WifiProp prop(u8"Arduino Lights", // as MQTT client id, should be unique per client for given broker
18-
u8"Room/My room/Props/Arduino Lights/inbox",
19-
u8"Room/My room/Props/Arduino Lights/outbox",
20-
"192.168.1.53", // your MQTT server IP address
21-
1883); // your MQTT server port;
18+
u8"Room/My room/Props/Arduino Lights/inbox",
19+
u8"Room/My room/Props/Arduino Lights/outbox",
20+
"192.168.1.53", // your MQTT server IP address
21+
1883); // your MQTT server port;
2222

2323
// Relays pinout
2424
#define LIGHT1 0
@@ -28,26 +28,38 @@ WifiProp prop(u8"Arduino Lights", // as MQTT client id, should be unique per cli
2828
#define LIGHT5 4
2929
#define LIGHT6 5
3030

31-
PropDataLogical blinking(u8"blink", u8"yes", u8"no", true);
32-
PropDataLogical led(u8"led");
31+
PropDataLogical lighting(u8"lighting", u8"yes", u8"no", false);
32+
PropDataLogical light1(u8"light1");
33+
PropDataLogical light2(u8"light2");
34+
PropDataLogical light3(u8"light3");
35+
PropDataLogical light4(u8"light4");
36+
PropDataLogical light5(u8"light5");
37+
PropDataLogical light6(u8"light6");
3338
PropDataText rssi(u8"rssi");
3439

35-
void blink(); // forward
36-
PropAction blinkAction = PropAction(1000, blink);
37-
3840
bool wifiBegun(false);
3941

4042
void setup()
4143
{
4244
Serial.begin(9600);
4345

44-
prop.addData(&blinking);
45-
prop.addData(&led);
46+
prop.addData(&lighting);
47+
prop.addData(&light1);
48+
prop.addData(&light2);
49+
prop.addData(&light3);
50+
prop.addData(&light4);
51+
prop.addData(&light5);
52+
prop.addData(&light6);
4653
prop.addData(&rssi);
47-
54+
4855
prop.begin(InboxMessage::run);
4956

50-
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
57+
pinMode(LIGHT1, OUTPUT);
58+
pinMode(LIGHT2, OUTPUT);
59+
pinMode(LIGHT3, OUTPUT);
60+
pinMode(LIGHT4, OUTPUT);
61+
pinMode(LIGHT5, OUTPUT);
62+
pinMode(LIGHT6, OUTPUT);
5163

5264
// At this point, the broker is not connected yet
5365
}
@@ -87,17 +99,12 @@ void loop()
8799

88100
rssi.setValue(WiFi.RSSI() + String(" dBm")); // https://www.metageek.com/training/resources/understanding-rssi.html
89101

90-
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
91-
92-
blinkAction.check(); // do your stuff, don't freeze the loop with delay() calls
93-
}
94-
95-
void blink()
96-
{
97-
if (blinking.value()) {
98-
led.setValue(!led.value());
99-
digitalWrite(LED_BUILTIN, led.value() ? HIGH : LOW);
100-
}
102+
light1.setValue(digitalRead(LIGHT1)); // read I/O
103+
light2.setValue(digitalRead(LIGHT2));
104+
light3.setValue(digitalRead(LIGHT3));
105+
light4.setValue(digitalRead(LIGHT4));
106+
light5.setValue(digitalRead(LIGHT5));
107+
light6.setValue(digitalRead(LIGHT6));
101108
}
102109

103110
void InboxMessage::run(String a) {
@@ -111,16 +118,16 @@ void InboxMessage::run(String a) {
111118
{
112119
prop.resetMcu();
113120
}
114-
else if (a == "blink:1")
121+
else if (a == "lighting:1")
115122
{
116-
blinking.setValue(true);
123+
117124

118125
prop.sendAllData(); // all data change, we don't have to be selctive then
119126
prop.sendDone(a); // acknowledge prop command action
120127
}
121-
else if (a == "blink:0")
128+
else if (a == "lighting:0")
122129
{
123-
blinking.setValue(false);
130+
124131

125132
prop.sendAllData(); // all data change, we don't have to be selctive then
126133
prop.sendDone(a); // acknowledge prop command action

0 commit comments

Comments
 (0)