Showing results for 
Search instead for 
Did you mean: 

Bool control if 2 are true and you press third the first one pressed should be false

Go to solution


I have problem with understanding how should i approach this issue, i could write it in regular programming language but in LabView i lack with experience. Thats why i decide to ask here.

So i got 4 bool controls. I decide to make 2d array in which i save bool value with timestamp when pressed didn't do that yet because i am stuck. I wanted to check if i truly can change value of the bool control which is in array, but when i get the element i have no idea how to change its value since it gives me back an indicator. I detect when 3rd value is pressed using XOR gate. First of all i want to know if my approach is correct and then it would be really helpful if someone could tell me how i can fill array and then change its element values.

Here is translated task i have to do.

Create four Boolean controls on the front panel and program them so that at most the last two activated controls are enabled. Pressing the buttons should sequentially turn the variables on and off until we try to activate the third one, at which point the earliest activated one goes off.
0 Kudos
Message 1 of 5

First of all, we generally don't do your homework for you.  Second, I suspect the original language for this assignment wasn't English, as I'm not entirely clear that I understand the proposed task (I can think of several different interpretations ...).  I think this says that there cannot be three controls all "On" at the same time, and that the order in which the Controls are turned on is important.


Take a piece of paper and a pencil, and make a drawing with 4 switches.  Start with all Off.  Make the next drawing with one on.  Make the third drawing with two on.  Decide how to make the 4th drawing (I suggest turning one of the "on"s off).  Keep going until you have 3 on -- how do you decide which to turn off?


Now do the same thing in LabVIEW.


Bob Schor

0 Kudos
Message 2 of 5
Accepted by topic author Jouzuu

1. Use an Event Structure to detect when the buttons were pressed.

2. Use an array to keep track of which buttons were turned on in what order.  You can use a Delete From Array to remove the element and a Build Array to add an element to the end.  This array should be saved in a Shift Register on your loop.


With that information, you detect a button press and verify it went TRUE.  If it went FALSE, search your array and remove the value corresponding to what just went FALSE.  If it did go TRUE, add the current button to the array.  If the array is now 3 or more, remove the first element and set that control's value to FALSE.  References and a Value property node could make this really easy.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 5

I figured it out it seems to work but i think i over do it. I used queue. adding or removing element from queue depending on what is value of pressed bool, then if there is more than 2 i remove 1st element. There is issue if i press buttons too fast it is bugged. How can i wait for iteration to finish? Should i just add simple wait or there is another way?

0 Kudos
Message 4 of 5

Thank you!!! That solution works perfectly with my solution it wasn't working so smoothly. I think its because queue works async but i will be really glad if someone could explain me my previous mistakes.

0 Kudos
Message 5 of 5