LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to toggle boolean with joystick button within while loop?

I'm initializing a joystick and then going into a loop where I acquire joystick information.  I want to be able to toggle a boolean indicator only when the button is pressed.  (Click - goes ON, release - stays ON, click - goes OFF, release - stays off and so on)

Does anyone have any ideas?

Thanks
0 Kudos
Message 1 of 4
(2,894 Views)

You need to add a shift register to the loop (by right clicking the loop wall) and use that to remember the state of the joystick button in the previous iteration. Then, you should perform your transition code only when the value of the button is different from what it was in the previous iteration.

You can also encapsulate this in a simple change detection VI. Have a look at Labuseful's site or at the OpenG comparison package for examples.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
Message 2 of 4
(2,888 Views)

attafire wrote:
> I'm initializing a joystick and then going into a loop where I acquire
> joystick information.  I want to be able to toggle a boolean
> indicator only when the button is pressed.  (Click - goes ON,
> release - stays ON, click - goes OFF, release - stays off and so on)
>
> Does anyone have any ideas?
>
> Thanks

Attafire:

It looks like 2 simple case statements would accomplish this task quite
easily. In the loop where you're aquiring joystick information have,
one case statement execute if the button is pressed and the LED is
already on. Have the second case statement execute if the button is
pressed and the LED is already off. Hope this helps...

0 Kudos
Message 3 of 4
(2,869 Views)

Well, since I'm in the process of learning about events I would say use event structure for a joystick press and then set it up to write the bool to a global variable.  That way you don't have to keep polling and using up that precious cpu.

 

Oh, and tst can you please check out my post on ctrlref during events?  You seem to know what's goin on with these event thingys... thanks

 

0 Kudos
Message 4 of 4
(2,866 Views)