@Aro1do
I like the idea of easily enabling and disabling buttons/switches, with visual indication (on app). A nice “lockout” feature that can be easily implemented for whatever reason.
But I don’t see any reason for Blynk to hard code that in… since we would probably still have to write some code to enable or disable the buttons anyhow… code is code, and not much would be needed.
Super simple, even I could do it … and here is how…
A int
line up front (for each item), assigning the variable to enable or disable… and this variable could be adjusted via code on the hardware side, or a “menu” in the app (with more buttons of course )
Corresponding lines in setup (for each item) to assign enabled/disabled colours, labels, etc.
And a single if()
statement added to each function to allow or disallow action.
I even included my Patent Pending “Flash an LED while the button is pushed, without stalling the rest of the code” routine. WARNING not to be over used lest everything come crashing down in a flood… and you blame me
// Two buttons, one to flash a RED LED, one to flash a WHITE LED
// Either button can be enabled or disabled with a 1 or 0 variable
#include <BlynkSimpleStream.h>
char auth[] = "authcodehere";
int v1E = 1; // V2 Button - Enable(1) Disable(0)
int v2E = 0; // V2 Button - Enable(1) Disable(0)
void setup()
{
Serial.begin(9600);
Blynk.begin(Serial, auth);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
if (v1E == 0) { // If disabled black out the V1 button, if enable set to your colour choice.
Blynk.setProperty(V1, "color", "#000000"); // Black
} else {
Blynk.setProperty(V1, "color", "#FF0000"); // Red
}
if (v2E == 0) { // If disabled black out the V2 button, if enable set to your colour choice.
Blynk.setProperty(V2, "color", "#000000"); // Black
} else {
Blynk.setProperty(V2, "color", "#FFFFFF"); // White
}
}
BLYNK_WRITE(V1) // Run this function when V1 button pressed.
{
if (v1E == 1) { // Check if disabled or not.
int pinValue = param.asInt(); // Get status of V1.
if (pinValue == 1) { // If status of V1 is 1 then do stuff in if().
digitalWrite(3, HIGH); // Turn on LED.
delay(20); // Wait 20 millis but remember you are holding up the show.
digitalWrite(3, LOW); // Turn off LED.
Blynk.run(); // Run rest of show in-between waiting for this loop to repeat or quit.
int pinValue = 0; // Set V1 status to 0 to quit, unless button is still pushed (as per below)
Blynk.syncVirtual(V1); // ...Then force BLYNK_WRITE(V1) function check of button status to determine if repeating or done.
}
}
}
BLYNK_WRITE(V2) // Run this function when V2 button pressed.
{
if (v2E == 1) { // Check if disabled or not.
int pinValue = param.asInt(); // Get status of V2.
if (pinValue == 1) { // If status of V2 is 1 then do stuff in if().
digitalWrite(4, HIGH); // Turn on LED.
delay(20); // Wait 20 millis but remember you are holding up the show.
digitalWrite(4, LOW); // Turn off LED.
Blynk.run(); // Run rest of show in-between waiting for this loop to repeat or quit.
int pinValue = 0; // Set V2 status to 0 to quit, unless button is still pushed (as per below)
Blynk.syncVirtual(V2); // ...Then force BLYNK_WRITE(V2) function check of button status to determine if repeating or done.
}
}
}
void loop()
{
Blynk.run();
}