05-15-2016 04:19 PM
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.
Solved! Go to Solution.
05-15-2016 04:47 PM
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.
05-15-2016 05:41 PM
Thanks for your help, it works.
05-15-2016 07:24 PM
Don't forget an event based solution, We can use "key down" and "key repeat" events.
See the attached primitive example.
05-15-2016 10:40 PM
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.
05-16-2016 09:15 AM
@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.... 😉
05-16-2016 02:59 PM
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.
05-16-2016 03:11 PM
@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.
05-16-2016 03:20 PM
05-16-2016 04:18 PM
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.