10-30-2015 07:00 PM
Hi everyone!
I have a problem about repeating a task in a case structure. I want to control two LED indicators in a sequence until I change the case.
Here is a clearer explanation of what I am trying to do:
LED#1 ->on (wait 100ms)
LED#2 ->off (wait 100ms)
LED#1 ->off (wait 100ms)
LED#2 ->on (wait 100ms)
....
How can I do this? In the vi I uploaded, there is a main while loop and a case structure in it. If the case is false both LEDs are off. If the case is true then LEDs should be as above.
Thanks for helping!
Solved! Go to Solution.
10-30-2015 07:47 PM - last edited on 12-16-2024 03:57 PM by Content Cleaner
It might help to better understand what your end goal is. Is this the end of the program, Blinking LEDs? Is this a homework assignment?
Your VI won't work because you're not understanding dataflow. The LED values don't trigger the True or False values until the data gets passed through the wires to the indicator terminals.
LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.
After you understand what's wrong with your VI, you may want to make it work better. In LabVIEW, you rarely need to use a sequence structure and you shouldn't because it leads to duplicating code and non-scaleability. The way around this is to use a For loop that loops 4 times where each loop assigns different boolean values according to your instructions above.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
10-30-2015 09:02 PM
This sounds like an incredibly easy state machine to put together. Have you looked into that architecture?
10-30-2015 09:23 PM
Honestly, I think state machine is too complicated for this specific application if all he needs is the LEDs to flash in that order once. If he plans to grow the code, then yeah, state machine.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
10-30-2015 10:43 PM
My actual VI's screenshot is attached. This is a lab project and I am controlling a set of valves and pressure regulators via Arduino and Labview. The LEDs stand for the valves in this case. I just wanted to simplfy it for you so that you guys could play with the VI and guide me.
There are 4 cases for the valves.
Case 1 = manual on/off
Case 2 = auto control (if a condition is satisfied the valves are on/off just for once)
Case 3 = This is the one I asked. The valves should be on/off for a period of time, until I move to case 4.
Case 4 = all valves are off
Now do you have any suggestions?
10-31-2015 11:38 PM
I did it after some thinking 🙂 It is really easy
11-01-2015 09:56 AM
@akifyalcinkaya wrote:
I did it after some thinking 🙂 It is really easy
Thinking is always good. Sometimes it helps to write down what you want to do in a way that your best friend, who does not know LabVIEW, will understand the problem -- for more complicated tasks, such a step can help clarify and organize your thinking.
Bob Schor
11-01-2015 11:17 AM - edited 11-01-2015 11:17 AM
@akifyalcinkaya wrote:
I did it after some thinking 🙂 It is really easy
I would recommend to do some more thinking (yes, it's easy!)
Here's a possible alternative implementation.
11-01-2015 11:52 AM
Thank you for the recommendation but my actual code is a bit more complicated and I need a case structure there. You can see the screenshot in the attachment.
11-01-2015 12:24 PM - edited 11-01-2015 12:26 PM
Ok, that's even worse because now you have a race condition.
Your "initial mass" global variable is read and written in parallel, but the immediate outcome differs depending on what occurs first.
Why is this a global variable at all? Are ther other VIs that also access it? For local use, you would just use a feedback node to store the reference value.
Please attach your actual VI, looking at a code picture never gives the complete information.
Why is there so much duplicate code??? You could calculate 255/80 once before the loop and multiply the controls with the result. Why do you think you need to do that three times per iteration?
You could even use a arrays of controls/indicators.
Your code is also broken because some output tunnels are not fully defined.
Your shift register serves no purpose because you never use its output.