LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help trying to get a joystick button to execute case structure only once per click

Solved!
Go to solution

Untitled.jpg

Any help would greatly be appreciated. Note: I have tried many things I have come across online for hours... I did try to find a solution myself.

0 Kudos
Message 1 of 5
(2,475 Views)

I just built a VI to do this with the FRC team I mentor; unfortunately, that code is on a team laptop and I don't have it. The idea is you use a while loop with an uninitialized shift register. The shift register maintains the previous state of the button. Each time you call the VI, you check if the previous button state was false and the current state is true, meaning the user just pushed the joystick button. If so, do whatever you needed to do. If you make this into its own VI and use it in several locations, make sure you set the VI to be re-entrant (VI properties, Execution category) otherwise it won't work as you expect.

 

The image below shows a very simple version that does only what you want. We made ours more complex with a reset input and an additional output so that it could toggle (press once to turn on, press again to turn off).

 

check button press.png

0 Kudos
Message 2 of 5
(2,464 Views)
Solution
Accepted by topic author JJay

I have modified and attached a VI snippet that may be useful.

 

also could refer to this URL

 

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

Message 3 of 5
(2,459 Views)

Hi JJay

 

I will recommend you to use an event structure that way your code will only be executed one time per event on the front panel. Here are a link with more information about the Event Structure and a example.

 

Regards.

Esteban R.

0 Kudos
Message 4 of 5
(2,435 Views)

Esteban.R wrote:

I will recommend you to use an event structure that way your code will only be executed one time per event on the front panel. Here are a link with more information about the Event Structure and a example.


This is definitely not an option. First, LabVIEW provides no way to trigger events on joystick buttons (at least that I've ever seen). Second, the VIs shown in the screenshot are from the FIRST Robotics toolkit, although there's no way to know that unless you've worked with an FRC team. The robotics code runs on a cRIO, which doesn't support user interface events.

0 Kudos
Message 5 of 5
(2,429 Views)