From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Repeat sending command while holding down a button

Solved!
Go to solution

This is like the volume button on some of the audio playing devices which have volume buttons instead of dials, if we press and hold the button, it will repeat senginf command to ramp volume up or down. I couldn't figure out how I can achieve this in LabVIEW, anyone has suggestions? Thanks.

0 Kudos
Message 1 of 18
(4,783 Views)
Solution
Accepted by topic author guangdew1

Use a switch until released button.

 

When the switch goes on, set yourself up with a timer that will continue to increment the value as long as the button is True.  When it goes to false, you can stop incrementing and stop the timer.

Message 2 of 18
(4,773 Views)

Thanks for your help, it works.

0 Kudos
Message 3 of 18
(4,763 Views)

Don't forget an event based solution, We can use "key down" and "key repeat" events.

 

See the attached primitive example.

 

 

Message 4 of 18
(4,732 Views)

altenbach,

 

It's a very nice example. Even though I only had the virtual button press in mind, I'll think about whether I can add this to my application. Thanks.

0 Kudos
Message 5 of 18
(4,713 Views)

@guangdew1 wrote:

Even though I only had the virtual button press in mind,....


Sorry, I cannot read minds,.. 😄

 

You were talking about "devices" with "volume buttons". For example, look at the side of your smartphone. If you hold the up or down button, the volume will change accodingly and that's how I understood the question.... 😉

0 Kudos
Message 6 of 18
(4,677 Views)

altenbach or RavensFan,

 

Thank you both for help. I did the "repeat.vi" as RavensFan suggested, it looks working okay. But when I place it into an event structure, it's no longer working. The "send" button will not bounce back so the loop keeps going, as shown in "repeat event.vi". I couldn't understand this kind of behavior, any suggestions? Thank.

Download All
0 Kudos
Message 7 of 18
(4,655 Views)

@guangdew1 wrote:

But when I place it into an event structure, it's no longer working. 


Get rid of the inner while loop and use the outer loop for everything. You get two events for a "switch until" button, one on press and one on release. Now simple toogle the timout value based on the button state and do your increments in the timeout event.

0 Kudos
Message 8 of 18
(4,648 Views)
Solution
Accepted by topic author guangdew1
Message 9 of 18
(4,644 Views)

altenbach,

 

Thanks for your example, otherwise I couldn't figure it out. I modified it a little bit so it can accomodate two buttons for both volume up and down. 

 

I tried you suggestions before this one, using key up and key down event, but it doesn't work, the button press will not trigger the event. Could you have a look and point out what is wrong? Thanks.

Download All
0 Kudos
Message 10 of 18
(4,627 Views)