LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read each button from a gamepad

Hi, what I would like to do is read input from a usb gamepad  and change a Color box and change text infront of the box. However, the controller outputs a t/f for each button.

 

(Button 1,2,3,4 will change color, and 5,6,7,8 will determine what text will display over the color box( 4 diff text displays))

My problem is how do I say "Def. If neither 1,2,3,4 are presses-black, If button 1 is pressed-blue, If button 2 is pressed-green...etc..."

 

I have tried a case structure, but they can only say T/F once, which would be fine but the color box can only accept one input... I have attached a picture of what I have that wont work, I need an alternative...

 

Thank you, 

Brent S.

0 Kudos
Message 1 of 7
(3,184 Views)

You can build array of the buttons and then give it to "search 1 d array" and then use a single case structure.

Message 2 of 7
(3,157 Views)

Like this

0 Kudos
Message 3 of 7
(3,154 Views)

Since your data is already a cluster you can use the Cluster to Array, then use the seach 1D array for a True eliminating the need for the build array.

0 Kudos
Message 4 of 7
(3,132 Views)

Since the buttons come in as booleans in a cluster, convert the cluster to an array, then use Search 1D Array to find the index of the first True. That index (0–3 for buttons 1–4) can directly drive a single Case Structure. Inside the case, output the color you want. If Search 1D Array returns -1, that means none are pressed, so set the color to black.

Same idea for buttons 5–8: convert to array, search for True, use that index to select which string to display (you can use another Case Structure or an array of strings and index it).

The key is: don’t wire each boolean separately into logic. Collapse them into an index first, then make one decision based on that.

0 Kudos
Message 5 of 7
(251 Views)

nevermind, I didn't look into Message 3

 

Spoiler
using "boolean array to number.vi"

button-array.png
remember: the case structur accepts ranges of numbers, so if you want button 1,2,3,4 is not pressed you define in the case selctor 1..8
0 Kudos
Message 6 of 7
(172 Views)

what are button 9 to 12 supposed to do?

can those be ignored?

 

can only one button be pressed at any time? 

or is it always a combination of one color button and one message button?

eg are button 1 and button 5 pressed together and you need to identify that case? 

 

if so, I think it is an option to interpret the button cluster of 12 booleans as one binary number via "boolean array to number.vi"

 

gamepade number 0 "no button at all"

Spoiler
alexderjuengere_0-1778579789647.png
under the assumption only one button can be pressed at any time, the first button pressed wins, and all other presses are ignored for the duration.

 

gamepad number 17 "button 1 and button 4 pressed" = "blue, message 4"

 

alexderjuengere_1-1778580008476.png

 

0 Kudos
Message 7 of 7
(122 Views)