Hello, I struggle with the code to understand Value Selector widget. So on the dashboard I have value selector 1,2,3 and green and red led. When I click on value 1, turn green light on red light off. When I click on value 2, turn red light on green light off. very basic. I am confused on to where to put that code. In the loop or in the OnValuechange section. Thank you.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/xxxxxxxxxxxxxxxxxxxxxxxxxxf
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int selection;
bool green;
bool red;
Variables 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.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(2, OUTPUT);
digitalWrite(2,HIGH);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
selection=0;
green= 0;
red=0;
}
void loop() {
ArduinoCloud.update();
// Your code here
if (selection =1) {
green = 1;
red = 0;
}
if (selection =2) {
red = 1;
green = 0;
}
}
/*
Since Selection is READ_WRITE variable, onSelectionChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSelectionChange() {
// Add your code here to act upon Selection change
}
/*
Since Green is READ_WRITE variable, onGreenChange() is
executed every time a new value is received from IoT Cloud.
*/
void onGreenChange() {
// Add your code here to act upon Green change
}
/*
Since Red is READ_WRITE variable, onRedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onRedChange() {
// Add your code here to act upon Red change
}
