BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Confirmation on certain buttons


#21

…and after confirmation, we can slide back to the 0 point with hardware. It can work like touch screen confirmation style.


#22

Or use 3-5 Step V widgets and make something like http://www.cablematic.com/photos/cablematic2015/bj67-2.jpg

and when you get at hardware the correct values… write to 0 all Step V one more time


#23

I’ve used the slider originally but moved to a double button press.

Looking at all the solutions here…

I guess in order of security (first being the least secure from accidentally pushing) but also in order of presentation and use (easier to harder)… This is my opinion only and does not necessarily reflect the view of others ha ha.

Double button push within 1 second (use latch button and code it to unlatch to make it more reliable, I can explain further if needed)
Push and hold the same push button for 1 second
Use a slider then require a button press to trigger
Use multiple vertical steps like a baggage code


#24

Look here for ways that I used timers to allow multiple button presses to achieve different results.


#25

I user two button widgets.
The first has to be pressed and held, when it is then switching the second button is activated. If the second button is pressed without the first then it has no effect.

I actually changer the colour of the second when the first is pressed, so that I know that its active.

When the second button is orange then it’s active.

Pete.


#26

Hi @PeteKnight,
Any chance you could post your code for your two button solution? I am trying to do the same to prevent accidental activation by a single button and am getting into all sorts of knots (and errors) with if statements and Blynk_Write commands. I haven’t been able to find any similar code to modify and my coding expertise just isn’t up to it. My project is remote actuation of a valve on a rainwater flush line. I have it working fine with a single button but the additional of the second “activator” button has me stumped.

Cheers
Steve


#27

just add a lambda function on the button to be hold down and a flag to tell the second button to lock or unlock


#28

Thanks for the response @Alexis_Cabrera. Lambda function? Sorry but I’m showing my lack of coding knowledge - not sure what you’re referring to. I have tried the following (this is just a snapshot of the complete sketch, capturing the action of the activator and actuator buttons)

 void myTimerEvent()
{
//If activator button is pressed, set button pin to high or low depending on button state, otherwise do nothing 
  BLYNK_WRITE(V5){
  if (Activatorbtn == 1){
  digitalWrite(btnpin, param.asInt()); // Sets btnPin HIGH or LOW depending on state of Button Widget.
  Serial.print("Btnpin:");
  Serial.println(btnpin);
  }
}
else
  Serial.print("Btnpin:");
  Serial.println(btnpin);

The Activatorbtn is the virtual button to be held down to activate (connected to virtual pin V6). The actuator button (conntected to virtual pin V5) sets btnpin high or low. btnpin is connected to digital pin 12 on the board.

Cheers
Steve


#29

something like that

BLYNK_WRITE(V6) {  // button to be held down to activate
  if (param.asInt()) {
   flag= 0;
    timer.deleteTimer(T1);
    T1= timer.setTimeout(1000L,  []() {//push 1 sec
             });  // END Timer Function
    flag= 1;
}

BLYNK_WRITE(V5) {  // actuator button 
 if (param.asInt()) {
if(flag=1){
//do something
      }
  }
}

#30

don’t forget to return flag = 0 after the execution of do something …


#31

as the flag is init to zero with V6 button it’s not needed, but maybe I 'm wrong :wink:

BLYNK_WRITE(V6) {  // button to be held down to activate
  if (param.asInt()) {
   flag= 0;

#32

Hi Stevve. I use Blynk in a very different way to most people, so all of the processing of the button logic is done in Node-Red, which will be of no use to you.

However, the same thing is easy enough to do C++
Start by making sure that the ‘activator’ button is set to ‘push’ rather than ‘switch’ mode.
When it’s pressed it will fire a BLYNK_WRITE(Vx) function event. Check that. ‘1’ has been received from the button and set an ‘active’ flag. If a ‘0’ is received (button released) then clear the ‘active’ flag.

With your main button, only process the action if your active flag is true.

Pete.


#33

it is a little strange that inside the delta type timer ( timeout ) unconditionally set flag =1 I think that this is unwonted but I am at work now with 0 free time to think deeper about…


#34

the flag is after timeout, not inside :wink:


#35

you must add this to detect release before 1 sec

// Button V6 has been released
  else {
    flag= 0;        // Reset the button press flag
    timer.deleteTimer(T1); // end timer
}

#36

…better now :wink:


#37

I am at work, so I can not try if my code is correct :blush:


#38

Hi all,
Many thanks for the thoughts on this.
@PeteKnight, the logic you described is exactly what I have in my head. My challenge has been converting this to code :grinning:
@Alexis_Cabrera I really appreciate you taking the time to put some code together. From what I can understand, the activator button has to be pressed for 1 sec to make it active and then then pressing the actuator button (while still holding the activator button down) will result in an action. Is this correct? Could this be simplified? For me, the chances that both buttons are pressed simultaneously are pretty low. The logic I was thinking of was (setting the activator button to push mode in Blynk) was that, if the activator button state = 1 (ie pressed) then write the state of the actuator button to the digital pin, otherwise the activator button state must be zero and do nothing. Would this work and how would it be coded?
I’ll give your code a try and see how I go.

Cheers
Steve


#39

Here’s a bit of pseudo code that may help get you started:

// Two buttons attached to virtual pins: Activator button = V10 and Main Button = V20. Activator button must be set to PUSH
// Press and hold the Activator button for the action of the Main button to have any effect

boolean Active_Flag=false; // Declare a global variable and set it to false by default

BLYNK_WRITE(V10)  // Automatically triggered when Activator button is pressed
{
  int V10_Button_Value = param.asInt(); // will be 1 if button pressed, 0 if button released

  if(V10_Button_Value ==1)
  {
    Active_Flag=true // Set the flag to true if the Activator button was pressed
  }
  else
  {
     Active_Flag=false // Set the flag to false if the Activator button was released
  }
}

BLYNK_WRITE(V20)  // Automatically triggered when Main button is pressed
{
  int V20_Button_Value = param.asInt(); // will be 1 if button pressed, 0 if button released

  if (Active_Flag)  // This next piece of code will only run if the Active_Flag == true
  {
      if(V20_Button_Value ==1)
      {
        // Do the stuff in here that you want to run when the main button is pressed (On)
      }
      else
      {
        // Do the stuff in here that you want to run when the main button is released (Off)
      }
  }
}

I’ve not compiled and tested this, so it may be full of syntax errors!

Pete.


#40

HI @PeteKnight ,
Many thanks for the code. Between yours and @Alexis_Cabrera, I think I am starting to understand how this works. I’ll have a play on the weekend and see how it goes.

Cheers
Steve