Skip to content

Commit

Permalink
Simplify multi value properties sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattia Bertorello committed May 15, 2019
1 parent fa62884 commit d1fc03b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions examples/MultiValue_example/MultiValue_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
The following variables are automatically generated and updated when changes are made to the Thing properties
bool Switch;
bool switchButton;
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
Expand Down Expand Up @@ -49,29 +49,29 @@ void loop() {
ArduinoCloud.update();
// Your code here

Switch = !Switch;
if (Switch) {
Loc = { .lat = latMov, .lon = lonMov };
Color = { .hue = hueRed, .sat = satRed, .bri = briRed };
switchButton = !switchButton;
if (switchButton) {
location = Location(latMov, lonMov);
color = Color(hueRed, satRed, briRed);
} else {
Loc = { .lat = latArd, .lon = lonArd };
Color = { .hue = hueGreen, .sat = satGreen, .bri = briGreen };
location = Location(latArd, lonArd);
color = Color(hueGreen, satGreen, briGreen);
}
delay(5000);
}


void onSwitchChange() {
void onSwitchButtonChange() {
// Do something
digitalWrite(LED_BUILTIN, Switch);
digitalWrite(LED_BUILTIN, switchButton);
}

void onColorChange() {
// Do something
Serial.print("Hue = ");
Serial.println(Color.getValue().hue);
Serial.println(color.getValue().hue);
Serial.print("Sat = ");
Serial.println(Color.getValue().sat);
Serial.println(color.getValue().sat);
Serial.print("Bri = ");
Serial.println(Color.getValue().bri);
Serial.println(color.getValue().bri);
}
14 changes: 7 additions & 7 deletions examples/MultiValue_example/thingProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const char THING_ID[] = "";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)

void onSwitchChange();
void onSwitchButtonChange();
void onColorChange();

bool Switch;
CloudLocation Loc;
CloudColor Color;
bool switchButton;
CloudLocation location;
CloudColor color;

void initProperties() {
ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(Switch, READWRITE, ON_CHANGE, onSwitchChange);
ArduinoCloud.addProperty(Loc, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(Color, READWRITE, ON_CHANGE, onColorChange);
ArduinoCloud.addProperty(switchButton, READWRITE, ON_CHANGE, onSwitchButtonChange);
ArduinoCloud.addProperty(location, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
}

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

0 comments on commit d1fc03b

Please sign in to comment.