08-19-2017 04:31 AM
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.....
Solved! Go to Solution.
08-19-2017 05:25 AM
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
08-19-2017 11:53 AM - edited 08-19-2017 11:57 AM
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.
08-19-2017 12:16 PM
@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:
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
08-19-2017 12:40 PM
Do you mean this, or is there any corrections, its not working
08-19-2017 01:14 PM - edited 08-19-2017 01:15 PM
@vicky95 wrote:
Do you mean this, or is there any corrections, its not working
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.
08-19-2017 01:29 PM
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:
Bob Schor
08-19-2017 02:14 PM - edited 08-19-2017 02:18 PM
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* ;))
*
08-21-2017 11:50 PM
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.
08-22-2017 12:21 AM - edited 08-22-2017 12:22 AM
@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.
May be this would help ?!!