I was thinking about a way to use a slider widget for both enable/disable and change a parameter of a feature of the sketch. The idea is: drag the slider to zero to disable the feature, drag the slider to any other value to enable the feature and set the parameter to this value (for example enable a Timer an set the time interval).
I came up with the solution below:
bool flagVar = false; // Flag variable for enabling/disabling a feature, a function etc.
int parameter = 0; // Define any parameter.
void setup() {
// Input resource connected with a slider widget.
thing["enable_disable"] << [](pson& in){
if (in.is_empty()){
if (flagVar){
in = parameter;
} else {
in = 0;
}
} else {
int var = in;
if (var == 0){
flagVar = false;
} else {
parameter = var;
flagVar = true;
}
}
};
if there is a more “professional” way to accomplish this task please leave a comment.