From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

If true condition for a button in labview

Let's say we want to say if UP button is pushed  increase the i value and if Down button is pushed decrease the i value. Is there a way to say if UP button is true do.... if Down button is true do... ?

0 Kudos
Message 1 of 26
(8,279 Views)

Of course there is.  Go to the first page of the Forums, find the "Getting Started with LabVIEW" link, and take the first two or three Tutorials, where Case structures and Boolean controls are certain to be covered.  Oops, in the redesign of the LabVIEW Forum, with the nice big buttons telling you to mark whether you are talking about LabVIEW 2017 or LabVIEW NXG, the Tutorial Section appears to have vanished.  I'll look for it ...

 

Hmm.  Seems to have vanished, replaced by the big Banner renaming this the LabVIEW Support Forum and asking you to choose LabVIEW 2017 or LabVIEW NXG.  I've already notified the Community Admin, requesting that the links to Getting Started with LabVIEW be put back where they were two weeks ago at the top of the LabVIEW Forum.

 

So Up and Down are Boolean controls.  Boolean controls have a "mechanical action", but if you choose a simple Push Button and change its label to "Up" or "Down", it will do the "expected" thing.  There is also a Case Statement to which you can wire the Boolean Control, giving you a True Case and a False Case.  Do you know about wires?  Wires carry data.  If a Wire has a value and you pass it into an "Increment" function (found on the Numeric Palette), it will be one higher when it comes out of the function.  Guess what the Decrement function does?  Obviously, you only want to do Increment if True -- the False case you just pass the wire through unchanged.

 

I deliberately did not "draw you a picture" -- open LabVIEW, type Control-N to bring up a new (blank) VI, put some Push Button controls on the Front Panel, maybe put a Starting Value (numeric) there, type Control-E to go to the Block Diagram (you'll see your controls sitting there), then right-click and look at the Palettes.  Start with Structures (see Case Statement?) and Numeric (see Increment?).  If you want to see the value in a wire, you just connect it to an appropriate Indicator which you can create on the Block Diagram by right-clicking the Wire and from the DropDown, choose Create, Indicator (the Indicator will now appear on the Front Panel, get back there with another Control-E).

 

Practice.  Explore.  Have fun.

 

Bob Schor

Message 2 of 26
(8,266 Views)

Sorry if I sound dumb..so create two loops one the condition is UP=true then ...

another loop condition is if Down = true

yes, I created two buttons then renamed the labels to up & down 

0 Kudos
Message 3 of 26
(8,264 Views)

@Canucks.canucks wrote:

Sorry if I sound dumb..so create two loops one the condition is UP=true then ...

another loop condition is if Down = true

yes, I created two buttons then renamed the labels to up & down 


Not to be too picky, but the "loops" on the Structures Palette are For and While.  "Loop" implies repetition (to me, anyway).  The Case Structure doesn't "loop", it "chooses", and implies selection, or choice.  But I applaud your enthusiasm ...

 

Bob Schor

Message 4 of 26
(8,260 Views)

aaaaaaaaaaaahh... My exact point..I wanna be able to choose not a loop that runs forever..thank you again

0 Kudos
Message 5 of 26
(8,257 Views)

@Canucks.canucks wrote:

aaaaaaaaaaaahh... My exact point..I wanna be able to choose not a loop that runs forever..thank you again


No, your loop needs to run as long as he program runs (which is, from the viewpoint of the program, forever :D)

To detect button presses, you need to poll the buttons (unless you are using an event structure, but let's not complicate things at this point :)).

This means the loop has to spin at a reasonable rate (e.g. 10x/second) and execute one of three cases, operating on a value held in a shift register.

  1. If no button has been pressed don't change the value
  2. If "UP" has been pressed, increment the value by 1.
  3. If "down" has been pressed, decrement the value by 1

If you want to change the value by exactly one for each button press, ensure the mechanical action is "latch when released". If you want to continually increment/decrement as long as the button is held down, use a "switch until released" mechanical action. Maybe you want something else, so look at all the options available.

Message 6 of 26
(8,226 Views)

thank you very much for your reply. lets say initial value of x=3, y= 5 . if i wanna say if up is pressed , x+y so 3+5 and now the new value of x is 8 ( so basically each time up is pressed the new value of x is  x=x+y)..how should I do?

I created a while loop inside my case structure with shift register but it didnt work

0 Kudos
Message 7 of 26
(8,072 Views)

You need to put the case structures inside the while loop (not while loop inside case structure). Then you will be able to access the shift registers from any case in your case structure.

 

If you are still having trouble, post your code and I can try to give you further guidance.

Message 8 of 26
(8,042 Views)

This is what I have so far..my case structure is not working.. my plan is every time we press the up button , resistance = resistance + Amount to add 

0 Kudos
Message 9 of 26
(8,040 Views)

Do you want Resistance to be a control or indicator? That is, are you expecting the user to enter data into it, or will you only be entering data into it programmatically?

 

If you change it to an indicator, then just wire directly into in inside your loop (wire from where you've updated it in the case structure to both the indicator and the output tunnel of the shift register). You don't need the feedback node.

 

If you are wanting the user to enter data into Resistance and also update it programmatically, then keep it as a control, but you will need to use a local variable to write to it. Right click on it and press Create >> Local Variable (you may also need to right click on the variable and press Change To Write). Then you won't need a shift register, you can just read from the control, then write to the local variable. However, I'd be careful with this way of doing it. You will need to think carefully and make sure this is really the behavior you want and be very careful as you make modifications to the program, because if you add another local variable somewhere else later, then it will overwrite the value you set and you need to make sure you don't have "races" between different parts of your program.

 

PS: If you're not opposed to it (eg: have a company policy against it or something) it's better to post actual code to the forum (the .vi file) rather than just a picture of it so we can open it and see better what's going on.

Message 10 of 26
(8,017 Views)