LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Exclusive Selection Using Multiple Buttons

Solved!
Go to solution

Hello, I am working on a state machine where in the idle state I want to have it wait for one of 3 buttons to be pressed and then it correspondingly moves to that state, essentially it starts up initializes some things then waits for the user to select what test thy want to run. So I need to have no buttons pressed to correspond to return to the idle state, button 1 sends it to run test 1 and so on for the other buttons.

 

I am more used to python programming, I would usually do this with a switch case where each button has a different input to that switch case. I have figured out 2 ways to make this work in LV but I do not like either.

 

First is take each bool from the buttons, change into 1/0, multiply each button by 1,2,4,etc to make binary out of it to get unique values then send that to a case structure but it seems like that should be much simpler than having to build my own binary converter. For this version I was relying on the button mechanical action to keep the buttons exclusive, barring the use of an auto clicker having the buttons set to switch until released will make it such that the time between and operator letting go of their mouse button and trying to click a different one it will have already executed the button selection code and have moved to the new state which each times the buttons get disabled and greyed out.

 

Or I could instead of having 3 buttons have a drop down enum with each test then tie that to a go button which actually passes what you select. While this is a simple and small structure it is absolutely horrible UI in my opinion. 

 

Anyone got a better means? I'm sure some of you wizards out these have a cleaner means than the binary.

 

Thanks,

Tim

 

TimHennesy_0-1706215727280.png

vs

TimHennesy_1-1706216284786.png

 

0 Kudos
Message 1 of 6
(1,209 Views)
Solution
Accepted by topic author TimHennesy

Take a look at "Radio Buttons" 

 

rqdseCapture.PNG

========================
=== Engineer Ambiguously ===
========================
Message 2 of 6
(1,193 Views)

If the objective is "At a certain time, look and see which of 3 buttons are pressed, and determine the next state", then radio buttons can work, as mentioned.

 

But if the objective is actually "At a certain time, pause execution until one of three buttons is pressed, and only then go to the next state depending on the button pressed" then you should actually be looking into using an Event structure.

0 Kudos
Message 3 of 6
(1,181 Views)

Thanks for the reply.

 

With this and the binary solution you hit the button, it does its thing then it automatically is back to idle as the button is only a momentary switch which is real clean and what i would hope to mimic with the radio button. 

TimHennesy_0-1706218894052.png

 

So with a radio button they do not have the option for a momentary switch, although they do allow for allow no selection so i at least do not need to add an Idle button, so I would need to set it such that after moving to the next state it then sets the radio button back to no selection via local variable or something? Would you agree that should get more or less the same functionality as the regular buttons but with eliminating the binary converter?

TimHennesy_1-1706219144517.png

 

0 Kudos
Message 4 of 6
(1,171 Views)
Solution
Accepted by topic author TimHennesy

For the radiobutton solution, make sure to configure it to "allow no selection", which is not the default.

 

 

Note that your first code picture has the problem that you need 2^3 cases, even though you only allow up to one boolean to be true at any time, i.e. 4 possible cases. Your multiplications and summing are pure Rube Goldberg. Just use "boolean array to number" instead (top code). To find the first true boolean, use the bottom code. The radiobutton is shown at the bottom and you can reset it to no selection via a local variable.

 

The code with the individual booleans could benefit from latch action buttons, depending on the requirements.

 

altenbach_1-1706220983688.png

 

 

 

 

Message 5 of 6
(1,164 Views)

Boolean array to number was exactly what I was looking for to eliminate my manual conversion. Thank you. 

 

Although I am now considering which I like better, the radio buttons or the separate ones, but I think between those 2 options I have everything needed to make this work clean.

 

Thanks for the help y'all

0 Kudos
Message 6 of 6
(1,154 Views)