Skip to content

Commit d1fc03b

Browse files
author
Mattia Bertorello
committed
Simplify multi value properties sketch
1 parent fa62884 commit d1fc03b

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

examples/MultiValue_example/MultiValue_example.ino

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
The following variables are automatically generated and updated when changes are made to the Thing properties
99
10-
bool Switch;
10+
bool switchButton;
1111
1212
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
1313
which are called when their values are changed from the Dashboard.
@@ -49,29 +49,29 @@ void loop() {
4949
ArduinoCloud.update();
5050
// Your code here
5151

52-
Switch = !Switch;
53-
if (Switch) {
54-
Loc = { .lat = latMov, .lon = lonMov };
55-
Color = { .hue = hueRed, .sat = satRed, .bri = briRed };
52+
switchButton = !switchButton;
53+
if (switchButton) {
54+
location = Location(latMov, lonMov);
55+
color = Color(hueRed, satRed, briRed);
5656
} else {
57-
Loc = { .lat = latArd, .lon = lonArd };
58-
Color = { .hue = hueGreen, .sat = satGreen, .bri = briGreen };
57+
location = Location(latArd, lonArd);
58+
color = Color(hueGreen, satGreen, briGreen);
5959
}
6060
delay(5000);
6161
}
6262

6363

64-
void onSwitchChange() {
64+
void onSwitchButtonChange() {
6565
// Do something
66-
digitalWrite(LED_BUILTIN, Switch);
66+
digitalWrite(LED_BUILTIN, switchButton);
6767
}
6868

6969
void onColorChange() {
7070
// Do something
7171
Serial.print("Hue = ");
72-
Serial.println(Color.getValue().hue);
72+
Serial.println(color.getValue().hue);
7373
Serial.print("Sat = ");
74-
Serial.println(Color.getValue().sat);
74+
Serial.println(color.getValue().sat);
7575
Serial.print("Bri = ");
76-
Serial.println(Color.getValue().bri);
76+
Serial.println(color.getValue().bri);
7777
}

examples/MultiValue_example/thingProperties.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ const char THING_ID[] = "";
77
const char SSID[] = SECRET_SSID; // Network SSID (name)
88
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)
99

10-
void onSwitchChange();
10+
void onSwitchButtonChange();
1111
void onColorChange();
1212

13-
bool Switch;
14-
CloudLocation Loc;
15-
CloudColor Color;
13+
bool switchButton;
14+
CloudLocation location;
15+
CloudColor color;
1616

1717
void initProperties() {
1818
ArduinoCloud.setThingId(THING_ID);
19-
ArduinoCloud.addProperty(Switch, READWRITE, ON_CHANGE, onSwitchChange);
20-
ArduinoCloud.addProperty(Loc, READ, ON_CHANGE, NULL);
21-
ArduinoCloud.addProperty(Color, READWRITE, ON_CHANGE, onColorChange);
19+
ArduinoCloud.addProperty(switchButton, READWRITE, ON_CHANGE, onSwitchButtonChange);
20+
ArduinoCloud.addProperty(location, READ, ON_CHANGE, NULL);
21+
ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
2222
}
2323

2424
ConnectionManager *ArduinoIoTPreferredConnection = new WiFiConnectionManager(SSID, PASS);

0 commit comments

Comments
 (0)