LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Latch button with press and hold delay

Hi, I'm trying to find a way to make a button with the following functionality:

 

  • If you press the button, and let go after less than x seconds the button remains false and no action.
  • If you press the button, and hold for more than x seconds, after x seconds (i.e. you could still be holding the button) a Boolean LED displays true.  When you let go of the button it stays true.
    • When you press the button again, and let go, the Boolean LED goes out and the button goes back to false, straight away.

Has anyone made something similar?  I have had a few attempts with no success at achieving all the functionality.

 

Thanks,

 

Neil
Certified Labview Developer
0 Kudos
Message 1 of 8
(5,469 Views)

What have you tried?  Seems like a good event structure with some shift registers to hold the value and tick counts should do it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(5,461 Views)

I've tried using an event structure and generating an event, then using the event time to determine how much time has passed. As below: press and hold_ generate events.png

This suceeds in meeting the button change but does not give an inidcation (via the boolean display) that the time has passed.

 

I've also tried manipulating the value of the button using property nodes and using a FGV counter to time:

press and hold_property nodes.png

This gives user indication that the time has passed via the boolean but is inconsistent with updating the button state.

 

NOTE: to run these snippets, you need to replace the bool Refnums controls with references to the button.

 

I've also tried having two buttons, one latch and one switch, and making one invisible, then switching which button is displayed, but this seems a bit convoluted.

 

Ideally, I want it to be self contained so I can drop it in to a GUI and not have to update existing event structures etc.

 

 

 

Neil
Certified Labview Developer
0 Kudos
Message 3 of 8
(5,437 Views)

@NEILBH wrote:

I've tried using an event structure and generating an event, then using the event time to determine how much time has passed. As below: 

This suceeds in meeting the button change but does not give an inidcation (via the boolean display) that the time has passed.


Use the Timeout.  You can dynamically set what the timeout should be by using a shift register wired to the Timeout of the Event Structure.  I don't see a need for the User Event.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(5,417 Views)

Here is my attempt, see attached

0 Kudos
Message 5 of 8
(5,412 Views)

Is it required for you to use latch vs switch?

0 Kudos
Message 6 of 8
(5,410 Views)

TToolDev01, your solution is close to what I want, I have modified it so that the button depresses on mouse down so that the user knows they have pressed the button, snippet below.

 

However, I was under the impression it is bad practice to execute code in the timeout case.  In this simple example it is OK, but to integrate this into a larger VI, I can not guarantee the timing of the execution of the timeout case, due to user generated events, locking the front panel etc.

 

Crossrulz, I think you are suggesting I utilise the timeout case as well, so I am happy to be persuaded that code in the timeout case is OK!

 

Natasftw, I'm not sure what you mean, but I am effectively wanting the boolean to change mechanical action based on time held, i.e. to latch initially, and then only after it has been held for a certain amount of time (say 2 seconds) change a switch action so it stays depressed.

 

The purpose is to prevent the user from accidently pressing this button and invoking the action; they have to conciously hold it (e.g. for 2 seconds) to invoke the response.  But I want the user to realise the button can be pressed and is not disabled, hence the state of the button changing when it is pressed for less than the time, but not invoking the response.

 

DelayedBoolean_mod.png

Neil
Certified Labview Developer
0 Kudos
Message 7 of 8
(5,390 Views)

You can remove a lot of that logic that is inside of your Timeout case by actually setting what the timeout should be.  So you key on the button's value change event.  With the button going true, you set your timeout to 2000 (2 seconds).  You then perform the desired actions on that timeout.  So when the button goes false, you set your timeout to be -1 (never time out).  You should also set the timeout to be -1 in the timeout case.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(5,373 Views)