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
(5,230 Views)
Solution
Accepted by 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
(5,220 Views)

Thanks for your help, it works.

0 Kudos
Message 3 of 18
(5,210 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
(5,179 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
(5,160 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
(5,124 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
(5,102 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
(5,095 Views)
Solution
Accepted by guangdew1
Message 9 of 18
(5,091 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
(5,074 Views)