LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to ON an LED when a switch is pressed and remain ON after switch is OFF and want to OFF LED when the same switch is pressed again, Help me.....

Solved!
Go to solution

I want to ON an LED when a switch is pressed and remain ON after switch is OFF and want to OFF LED when the same switch is pressed again.

I am already tried by using flip flops but i am failed. I am using Lab View  2012 version.

Help me.....

0 Kudos
Message 1 of 11
(11,300 Views)

So where is your While Loop with a Stop Control and a Wait (to slow it down)?  You don't ever want to rely on the Run Continuous button (I don't think I've ever pushed it) nor on the Abort button (if you push this, it is a clear indication that your LabVIEW code lacks the ability to stop itself!).

 

Let's analyze the problem.  You have a Boolean Control (why not name it "Switch" to help you understand its function?) that, when you press it, is supposed to change the state of a Boolean Indicator (why not name it "LED"?).

 

Draw a While Loop, right-click the Stop indicator and choose "Create Control" (which LabVIEW will conveniently label "stop", drop a Wait (ms) function from the Timing Palette inside, and wire 10 (ms) to it.  Since we're doing this step-wise, right-click the index ("i") and create Indicator (change its name to "Loops").  Now run this VI -- notice that Loops counts up at 100 counts/sec (because you wired 10 milliseconds to the Wait function) and continues until you press Stop.  This is the framework for solving your problem.

 

So create a Switch and an LED, and put both in the While loop.  The LED needs to "stay on" or "stay off", i.e. it needs a memory.  In LabVIEW, this is usually accomplished with a Shift Register (which is found on While and For loops).  Create one.  Since you are "remembering" a Boolean value, wire Boolean False to the Shift Register from the "outside" (left side) of the While Loop and notice the Shift Register becomes Green, the color of Booleans.  Put the LED to the right of the While loop and branch a wire from the Shift Register to it.

 

So what does the Switch do?  When it is pushed, it changes the switch.  How do you change a Boolean?  [Left as a what-I-hope-is-trivial exercise for the Reader].  How do you "gate" an action so it only occurs "when it is pushed"?  This should also be obvious, but just in Case, I'll bury a hint in this sentence.

 

Now run your code!  Does it work?  [The answer should be "No, it does weird things!"].  Do you know about the Mechanical Action properties of Boolean Controls?  No?  Click on Help, LabVIEW Help, and in the Index, find Mechanical Action of Boolean Controls and Indicators.  Try "Latch when Pressed", but not before you understand what it means!

 

Bob Schor

0 Kudos
Message 2 of 11
(11,278 Views)

Thank you for replaying. this is a small portion of my program. i will check latter all the things that you said and i will replay. would you please post the program for the conformation.

0 Kudos
Message 3 of 11
(11,245 Views)
Solution
Accepted by topic author vicky95

@vicky95 wrote:

Thank you for replaying. this is a small portion of my program. i will check latter all the things that you said and i will replay. would you please post the program for the conformation.


I apologize for writing unclearly.  Please tell me what concepts you do not understand:

 

Let's analyze the problem.  You have a Boolean Control (why not name it "Switch" to help you understand its function?) that, when you press it, is supposed to change the state of a Boolean Indicator (why not name it "LED"?).

 

Do you know how to change the name of a Control or Indicator (like "Boolean" to "Switch")?  Right-click the label to select it, then type in the new name.

 

Draw a While Loop, right-click the Stop indicator and choose "Create Control" (which LabVIEW will conveniently label "stop", drop a Wait (ms) function from the Timing Palette inside, and wire 10 (ms) to it.  Since we're doing this step-wise, right-click the index ("i") and create Indicator (change its name to "Loops").  Now run this VI -- notice that Loops counts up at 100 counts/sec (because you wired 10 milliseconds to the Wait function) and continues until you press Stop.  This is the framework for solving your problem.

 

If you don't know how to "Draw a While Loop", there's not much point in continuing, so I'll assume you can do this.  I'll also assume you know what I mean by the "Stop indicator".  Hmm -- now that I'm trying to explain these things, I realize anyone who has ever done anything with LabVIEW and knows the terms "Front Panel", "Block Diagram", and how to "see" the Function Palettes must understand this stuff.  So what is really your problem?  Are you asking me "Please do my homework for me"?  Are you saying "I'm too busy do put any effort into this ..."?  Maybe you are home, and your home PC doesn't have LabVIEW, but you are so eager to understand this that you don't want to wait until Monday -- that must be it.  OK, so here's what you do:

  • Take a Pencil and a Piece of Paper (I recommend Letter or A4 size).
  • Draw a While Loop.  Put a little octagonal Stop sign in the bottom left.  Draw a little square box, label it "Stop", and wire it to the Stop indicator.
  • Draw a Shift Register -- a little box on the left and right edges of the While loop with an up-triangle in one and a down-triangle in the other.
  • Draw a little box and label it "Switch", another one and label it "LED".  Note that when you place a Control or Indicator in LabVIEW, you can move them around much easier than you can with pencil and paper (no need for an eraser).
  • Use your imagination to finish the rest of this. 

So create a Switch and an LED, and put both in the While loop.  The LED needs to "stay on" or "stay off", i.e. it needs a memory.  In LabVIEW, this is usually accomplished with a Shift Register (which is found on While and For loops).  Create one.  Since you are "remembering" a Boolean value, wire Boolean False to the Shift Register from the "outside" (left side) of the While Loop and notice the Shift Register becomes Green, the color of Booleans.  Put the LED to the right of the While loop and branch a wire from the Shift Register to it.

 

So what does the Switch do?  When it is pushed, it changes the switch.  How do you change a Boolean?  [Left as a what-I-hope-is-trivial exercise for the Reader].  How do you "gate" an action so it only occurs "when it is pushed"?  This should also be obvious, but just in Case, I'll bury a hint in this sentence.

 

Bob "Wearing my Professor Hat" Schor

0 Kudos
Message 4 of 11
(11,238 Views)

Do you mean this, or is there any corrections, its not working

0 Kudos
Message 5 of 11
(11,233 Views)

@vicky95 wrote:

Do you mean this, or is there any corrections, its not working


Capture

 

This will not work, because the controls is read only once before the loop starts and the indicator is only updated once the loop has finished. It is called "dataflow".

 

Do a few LabVIEW tutorials before proceeding.

0 Kudos
Message 6 of 11
(11,218 Views)

That's a start.  Next time, attach a VI as it is very difficult to test LabVIEW code by executing a picture (unless, of course, it is a LabVIEW Snippet).  There is a reason (or "logic") behind my suggestions -- I'm trying to teach you Good LabVIEW Habits, as I'm more interested in helping you become a decent LabVIEW user/developer than on your getting a good grade.

 

So:

  • Rename the Control to "Switch", the Indicator to "LED".
  • Break the wires connecting Switch and LED to the Shift Register.  Notice that the Shift Register should turn Black (no known data type) -- I told you how to fix that, so do so. 
  • Remember the fundamental LabVIEW Principle of Data Flow -- if the Switch and LED are outside the While Loop, as long as the While Loop is running, nothing you do to Switch will matter (do you understand why that is?  Think about Data Flow) and no data will flow to the LED Indicator (do you understand why that is?  More Data Flow).
  • Since you want the Switch and LED to respond "all the time", put them where they have to be (think Data Flow).  Don't worry about wiring them yet (though my instructions are pretty clear, if you want to give it a try), but feel free to make these modifications and post the resulting VI (I absolutely promise to not look at any attached pictures).  I'll be checking back ...

Bob Schor

0 Kudos
Message 7 of 11
(11,214 Views)

OK, I was looking at your first code and it is apparent that you think that LabVIEW is a circuit simulator (!).

 

This is wrong! LabVIEW is a full featured programming language that uses graphical code to represent computer instructions and uses the principles of dataflow to determine execution order. Graphical code has many advantages, for example you can program several independent parallel processes on the same diagram if needed.

 

A simpler problem would be to change the switch to latch action (it will be true until the code reads the new state and then switches back to false automatically). Would that be sufficient? If you want a switch action boolean (as you currently have), you simply need to toggle the output whenever the switch goes from FALSE>TRUE. All you need for that is code the size of a postage stamp and it probably has been posted before here (I have an image in my image library, but I don't know where it has been posted before* ;))

 

*

Spoiler
Maybe this can give you some hints 😄

 

 

 

 

0 Kudos
Message 8 of 11
(11,206 Views)

I don't need just a true false switch, its already in it, i need a switch which will ON when i press it and remains in the same state when i released. And must go to false state when i pressed again.

0 Kudos
Message 9 of 11
(11,119 Views)

@vicky95 wrote:

I don't need just a true false switch, its already in it, i need a switch which will ON when i press it and remains in the same state when i released. And must go to false state when i pressed again.


Robot surprised

switch.PNG

May be this would help ?!!

0 Kudos
Message 10 of 11
(11,112 Views)