05-01-2011 11:29 PM
Hi, I'm new to LabVIEW and I'm having a little problem with it. I have one LED and four switches. What I need is when I turn on switch 1, the LED light up for 1 second, when I turn on switch 2 the LED light up for 2 seconds, when I turn on switch 3 the LED light up for 3 seconds, and when I turn on switch 4 the LED light up for 4 seconds. Also, the LED should light up for either 1,2,3, or 4 seconds accordingly even if I turned the switch on for more than 4 seconds or off immediately. I used a case structure to do this but I don't know how to make the LED stay on for the appropriate time. I was thinking about use the elapsed time but I don't know how to wire it. Any help would be appreciated and thanks in advance.
-Sunny
05-02-2011 12:15 AM - edited 05-02-2011 12:15 AM
Hi,
Check the attached VI. I think this must be the solution..
Regards,
Nitzz
(Kudos are always Welcome)
05-02-2011 12:18 AM
You will need to provide some clarification:
More importantly, what is the purpose of this program? Is this homework? 'Cause it certainly looks like it, as I've seen this question before. And it was homework. Not saying it is. But it certainly looks like it.
05-02-2011 12:20 AM
@NitzZ wrote:
Hi,
Check the attached VI. I think this must be the solution..
It would be, if you like forcing a user to wait 4 seconds before they can stop a program. What happens if the time is supposed to be 20 seconds? Do you think someone is going to like sitting there for 20 seconds before a program stops?
05-02-2011 12:39 AM
@NitzZ wrote:
Hi, I'm new to LabVIEW and I'm having a little problem with it.
Try this, but make sure you understand every little bit of it. You are not very clear with the specifications, so modify as needed.
@NitzZ wrote:
Check the attached VI. I think this must be the solution..
What's up with all the value property nodes? Why don't you use local variables instead???
05-02-2011 12:45 AM
Hi,
Thank you altenback and smercurio for the review...
@altenbach : Actually I was told by me seniors that local variables use more memory than property node value. So I started doing this. If you don't mind, can you tell me what is the difference between both and which is the ideal one..
@smercurio : I am sorry, I didn't think about it. Yes you are right about making user wait. That is wrong on my part. Any suggestions?
Regards,
Nitzz
05-02-2011 12:49 AM
Nitzz wrote:@altenbach : Actually I was told by me seniors that local variables use more memory than property node value. So I started doing this. If you don't mind, can you tell me what is the difference between both and which is the ideal one..
Well have your "seniors" read e.g. point number 6 in this post.
(Memory is irrelevant for scalars anyway ... )
05-02-2011 12:54 AM
@altenbach : Thank you for the quick reply and the thread link.. I will go through it and get more information about locals and property node values..
Regards,
Nitzz
05-02-2011 01:53 AM
Thanks a lot for all the help.
The switches are not mutually exclusive. If there's an action going on, then anything pressed before the end of that action should be ignored. So if the LED should light up for 4 seconds, then no matter what happened within those 4 seconds, the LED is always on for 4 seconds and then off, the time does not add up.
This is a model I'm going to use for my project. What I'm really doing is using 4 sensors to control 1 motor. So basically depending on which sensor triggered, the motor should run for the time that is set for that sensor (moving an object for certain distance). If another sensor is triggered before the motor stops, that trigger is ignored. I believe this LED example would be very similar to what I need as I'm still waiting for my NI USB-6008 to arrive.
05-02-2011 11:20 AM - edited 05-02-2011 11:22 AM
What you can do is place the code of the button event (except the button terminals) in a case structure so it only executes if the timeout is -1.
If the timeout is not -1, keep the LED lit and reduce the timeout value accordingly. You need to keep track of the tick count in a seperate shift register and dynamically recalculate the remaining timeout.
Here is an old example (from the end of this old discussion) that could gove you some ideas about that last point.