LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use local variable of a boolean to change the status of the boolean when some conditions are triggered.

Solved!
Go to solution

The picture is what I have now. There is a while loop outside of it and It is a small independent part of a big project. The operation of the boolean is "Switch when pressed" and it has to be. I am new here and I apologize that I can not directly upload the whole VI, due to the copyright.

 

 

The logic is that when the Boolean (x1 / x4) is true, it will give either 3 or 4 as output, which according to the case 3 and case 4 in the case structure. The x2,x3 and x5 are the limit that use to change the case from 3 or 4 to 0 when the limit is triggered, when the pump is full or empty and the movement should stop, which is case 0.

 

The function itself doesn’t have any problems and the movement will stop when it should, but we have to click the Boolean again to turn the function status OFF, which is not user friendly. 

 

What I want is that when the output of the formula node(y) changes from either 3 to 0 or 4 to 0, let the Boolean also change from true to false.

 

I use shift registers to get the value of y (last loop) and y’(this loop) and use “And Array element” to check if y=3 or 4 and y’=0 happen at the same time in y’( this loop). If this is true, set local variable of “Refill to full” and “Dispense to empty” be false. However, this doesn’t work.

 

 

Welcome any comments or suggestions! Thanks!

0 Kudos
Message 1 of 10
(3,488 Views)

@Qu2333 wrote:

I use shift registers to get the value of y (last loop) and y’(this loop) and use “And Array element” to check if y=3 or 4 and y’=0 happen at the same time in y’( this loop). If this is true, set local variable of “Refill to full” and “Dispense to empty” be false. However, this doesn’t work.


It would help to see the non-working code. You don't need to attach the full VI, just a working minimal copy.

Most of your descriptions are ambiguous. There is no case structure.

What is the loop rate? What does the user do? How should the program react to the user interactions? Where do the various orange X's come from? What do they represent? What changes them?

 

Somehow, it would seem much easier to use graphical code instead of formula nodes. 

 

0 Kudos
Message 2 of 10
(3,470 Views)

I see. I realize that I make this problem too complicate, which is not necessary. The attachment is the simplest version of my problem. Is there a way that I can change the button back to False after the user pressing it and making it be true, beside clicking the button again or change the operation of the button?

0 Kudos
Message 3 of 10
(3,451 Views)

I think you need to go back though some of the beginner tutorials as this is a basic boolean control property called "mechanical action"

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 10
(3,442 Views)

You can write a false constant to the local variable of the control.

 

But the example you attached is just too simplified to make it look like you should be using anything but latch action.

0 Kudos
Message 5 of 10
(3,440 Views)

First of all, thanks for the comment. But I clearly state in my problem that I know change the operation logic of the button will works and that is not what I want, because the other parts of the VI that relate to this button require I use "switch when pressed". Anyway, I will think about that, thanks.

0 Kudos
Message 6 of 10
(3,428 Views)
Solution
Accepted by topic author Qu2333

Yes, you would write to a local variable of the boolean. Not sure why you said it does not work. (Of course place a reasonabe delay inside the loop, no need to spin it as fast as the computer allows).

 

 

altenbach_1-1590861124211.png

 

0 Kudos
Message 7 of 10
(3,423 Views)

@RavensFan wrote:

You can write a false constant to the local variable of the control.

 


The specs in the first post were.

 

QUOTE: "The operation of the boolean is "Switch when pressed" and it has to be."

 

(Yes, maybe it is based on a misconception and does not have to be, but that's a different discussion 😉 Often latch action is not possible because of local variable and value property (over-)use).

0 Kudos
Message 8 of 10
(3,422 Views)

Ah! Using a case structure to set the local variable! I think that is exactly what I want. I forgot that I can leave one of the case empty! Thanks so much!

0 Kudos
Message 9 of 10
(3,418 Views)

Of course as discussed, if you really require switch action, most likely the value is also polled elsewhere (eg. via even more locals or value properties). In my code it switches back nearly immediately and it is unlikely that the transient TRUE is seen elsewhere unless they use an event structure (which would work just fine with latch action). I would recommend to invest in a more robust code architecture overall. Currently, this is basically "whac-a-boolean". 😄

 

0 Kudos
Message 10 of 10
(3,409 Views)