Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8acb151

Browse files
authoredMay 16, 2019
Merge pull request #65 from arduino-libraries/simplify-multivalue-sketch
Simplify multi value properties sketch
2 parents fa62884 + f4c60ad commit 8acb151

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed
 

‎.travis.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ before_install:
5757
- arduino --install-library RTCZero
5858
- arduino --install-library WiFi101
5959
- arduino --install-library WiFiNINA
60-
- buildExampleSketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/$1/$1.ino; }
61-
- buildExampleUtilitySketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/utility/$1/$1.ino; }
60+
- buildExampleSketch() { arduino --verify --board $BOARD $PWD/examples/$1/$1.ino; }
61+
- buildExampleUtilitySketch() { arduino --verify --board $BOARD $PWD/examples/utility/$1/$1.ino; }
6262
install:
6363
- mkdir -p $HOME/Arduino/libraries
6464
- ln -s $PWD $HOME/Arduino/libraries/.
@@ -67,7 +67,9 @@ script:
6767
- buildExampleSketch ArduinoIoTCloud_Travis_CI
6868
- |
6969
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ];
70-
then buildExampleSketch WiFi_Cloud_Blink;
70+
then
71+
buildExampleSketch WiFi_Cloud_Blink;
72+
buildExampleSketch MultiValue_example;
7173
fi
7274
- |
7375
if [ "$BOARD" == "arduino:samd:mkrgsm1400" ];

‎examples/MultiValue_example/MultiValue_example.ino

+13-13
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.
@@ -26,7 +26,7 @@ void setup() {
2626
initProperties();
2727

2828
// Connect to Arduino IoT Cloud
29-
ArduinoCloud.begin(ArduinoIoTPreferredConnection, "mqtts-sa.iot.oniudra.cc");
29+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
3030

3131
/*
3232
The following function allows you to obtain more information
@@ -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

+7-7
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)
Please sign in to comment.