08-19-2010 04:56 PM
I have two identical while loops in series. Each as a timer and a timer-expired LED indicator. When I run, the first LED lights and then the second LED. When I re-run, the first LED resets and the second LED stays lit. Once the first while loop completes, then the second LED resets and eventually times out and lights. How can I get both LEDs to reset immediately at run time?
Solved! Go to Solution.
08-19-2010 05:10 PM
For the second led create a local variable, change it to write, place it before both while loops and wire a false (booleon) to it.
08-19-2010 11:33 PM
Hope this helps
08-20-2010 06:21 AM - edited 08-20-2010 06:21 AM
Having while loops in series is often a sign of poor program design. Better would be a single loop designed as a state machine. Now none of this extra code is needed.
Can you show us your program?
08-20-2010 06:24 AM
@Dark Hollow wrote:
How can I get both LEDs to reset immediately at run time?
There is also an execute option called "clear indicators when called". That might be all you need.
08-20-2010 07:45 AM
Using Local Variables is BAD ADVICE.
There is no need for it.
As Altenbach suggested, using a state machine with shift registers is the appropriate way to go.
There are plenty of examples on this forum that shows what you want to implement.
Some of these examples were written by the top contributors to this forum and show appropriate implementation of the code.
The state machine would have a reset state that resets all LED values at once. The new values would be written to the the wire (which is the variable in LabVIEW) and passed to the beginning of the next iteration through the shift register (right click on edge of loop and select it). You can update the display immediately after the state completes at the right of the Case Structure, or if you want to get fancy, you can have a refresh display state that is triggered by time or other events and you can refresh the display after several states have been executed. There is no limit to how creative the code can be, as long as it is done right. 😉
08-20-2010 07:46 AM - edited 08-20-2010 07:53 AM
@omprakash wrote:
Hope this helps
What the heck is this? This is not a solution for what the person is asking? Why have a loop if it either stops at the first iteration if LED is FALSE? And once you set the value for LED2 it will not reset unless you stop and run the VI again. Nevermind the fact that the second loop will also stop as soon as it is FALSE, which is what the value will be when the first loop ends. Did you try running your example? It's really useless.. Try running it. Learn from it and try to understand the dataflow by first running it and repeating the execution with highlight execution turned ON.
08-20-2010 07:58 AM
Lots of great ideas. Thanks to all. This one is the best for my application.
08-20-2010 08:01 AM
By "this one," I meant the "clear indicators when called" option. Simple and direct. Thanks.
FYI, my application is not using serial while loops. I just used that as a simple example to demonstrate the LED reset issue.
08-20-2010 09:19 AM
@Ray.R wrote:
Using Local Variables is BAD ADVICE.
I agree that it's bad advice in general. However, Viper's idea is a valid one - in general - maybe not for this application. One of the (few) appropriate uses for Locals are at the beginning of a program for initialization. I still would not advise the use of Locals, the same way I would not advise my son to drink beer, even though I do.