hi @Gunner ,
I’m sorry for that, as my question was related to the code of them I thought it was the right place.
I try to include BlynkTimer and to test it again.
Hi @Gunner,
your code is not perfect… I’m joking!
I would like to have just 10% of your knowhow of Blynk programming, however this is wath I did.
Your code switch to "True" just moving the slider up to 51% even without reaching the end and doesn’t come back if you move it below the 50%, it stay there.
What I did is, adding 1 decimal to the Slider Widget in order to have also values between 0 and 1, in this way it will be "True" only if it reache the end and comes back if you leave it in whatever position.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet2.h>
#include <BlynkSimpleEthernet2.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "1234567890abcdefg0987654321"; // blynk-cloud.com
BlynkTimer timer;
WidgetLED redLed(V1); // LED Widget
BLYNK_WRITE(V0) { // Slider as "secure" Button - Set 0/1, Decimals #.# and Send on Release ON
float slided = param.asFloat();
if (slided == 1) { // The slider is at the end
digitalWrite(D4, 1); // Open the Garage
redLed.on();
timer.setTimeout(500L, []() { // non-blocking delay timer
Blynk.virtualWrite(V0, 0); // Resets Slider LOW
Blynk.syncVirtual(V0); // Processes Button "release"
digitalWrite(D4, 0); // Reset the Relé
redLed.off();
}); // END delay timer
} else {
if (slided >0 && slided <1) { // The slider has been moved
Serial.println(slided);
Blynk.virtualWrite(V0, 0); // Resets Slider LOW
Blynk.syncVirtual(V0); // Processes Button "release"
}
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// You can also specify server:
//Blynk.begin(auth, "blynk-cloud.com", 80);
//Blynk.begin(auth, IPAddress(1,2,3,1), 8080);
// For more options, see Boards_Ethernet/Arduino_Ethernet_Manual example
pinMode(D4, OUTPUT); // set pin 4 as output for Relé
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
I tested the code of @Blynk_Coeur too but yours is more what I was looking for.
Try it out, it seems a real Sliding Button now.
It’s a workaround and it works fine, but if the Blynk Staff will include a Widget in the App, people don’t have to program a lot and nobody will ask again for a “Secure Button” or, even worse, reopen old posts like I did.
@Blynk_Coeur’s code could be adapted to almost any of the input widgets. You just basically have each of the corresponding BLYNK_WRITE() commands follow the format.
I agree that it is pretty clever indeed. And quite simple.
Blasphemy … I worked long hard minutes to come up with that
Yes, it was quick and dirty… Getting around the 51% is just a matter of stretching out the range, but only reacting to the final value. And same with moving less than 50% as an else value could activate return to 0.
EDIT - Oops, now I look at your code and see you already did similar to all that. Good job
That use of the #.# was sooo simple… I am stealing that for my code examples
PS, Sooo many options with code… and on that note …
I don’t find code a workaround, rather it is ultimate customisable control If I ever learn to code quality App GUIs I would be self sufficient. But for now Blynk is by far the best to work with overall.