LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event for long time button-press?

Solved!
Go to solution

Hello everybody!

 

Is it possible to set different events in an event structure for the same button?

More precisely I want to have 2 events: the first if the button is pressed regular and a second if the button is pressed for more than 5 seconds.

 

I have been searching the forum but did not find and threats concerning this topic.

 

Thanks for your help!

0 Kudos
Message 1 of 17
(3,336 Views)
Solution
Accepted by topic author jobauer

Hi jo,

 

first event is generated by "value change" of that button. Store the current state of the button in a shift register.

2nd event is generated by using the TimeOut event: here you only need to check the current button state, if TRUE you can do your event handling code…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 17
(3,318 Views)

Thank you GerdW for your replay!

First i solved it with this method i found by adding an case structure:

https://decibel.ni.com/content/docs/DOC-11639

 

But actually your method works better!

Thanks

0 Kudos
Message 3 of 17
(3,311 Views)

Because you cannot add an event timeout if you use the method i just posted...

0 Kudos
Message 4 of 17
(3,310 Views)

Hi jo,

 

that example does just what it claims to: it calculates the time a button was pressed - after the button has been released.

 

You cannot use this for your task as you want to generate an event while the button is still pressed!
That's why I suggested to use "value change" and "TimeOut" events instead…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 17
(3,307 Views)

Yes that was exactly my problem 🙂

0 Kudos
Message 6 of 17
(3,292 Views)

Dear jobauer, Dear GerdW,

 

Could you please post a runnable program which solves jobauers problem? I have some difficulties to adapt GerdWs solution to my program. So, I would be happy to see the code.

0 Kudos
Message 7 of 17
(3,106 Views)

Hi partial,

 

what kind of difficulties do you see?

What's the problem to incorporate two event cases in your code? How does your code look like?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 17
(3,104 Views)

Hi GerdW,

 

Thanks for the quick reply.

At the moment I use in my code an event structure and test if there is a value change of my button. If there is a value change, some action will happen (some data will be deleted). This works fine so far.

Now I want that some other action will happen (more data will be deleted) if the same button is pressed for more than e.g. 5 s (the same action as before may still happen in this case).

I really do not understand how I can achieve this with the Timeout event and a check of the current button state.

 

I hope you understand my problem better now. If not, then I will try to write a simplified example code of my problem (the whole program is too complex to post here).

0 Kudos
Message 9 of 17
(3,097 Views)

Hi partial,

 

have your timeout event wait for 5s and check the button state in the timeout event. If the button state didn't change the user still presses the button…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 17
(3,095 Views)