01-23-2021 06:53 PM
I have an emulation of ship navigation lights to check logical pattern construction. I would like to blink lights in particular patterns, but not in the standard fixed identical time for the lit and dark periods one would get in a loop with a wait. What I envision is ON for 250ms and OFF for 1, 2, 5, 10 seconds selectable.
Anyone done anything like that?
Solved! Go to Solution.
01-24-2021 10:17 AM
I haven't specifically done that, but it is easy enough.
Are you asking a specific question? This sounds like homework. What have you tried so far?
01-24-2021 03:10 PM - edited 01-24-2021 03:14 PM
I agree, this looks like a great beginner exercise doable in a few minutes (I just did!). How much LabVIEW experience do you have?
Some things to decide. Should there be a pulse a t=0? What should happen if the duration is changed from 10s to 1s, two seconds after the last pulse? (e.g. wait for the full 10 seconds or switch immediately?) etc.
01-24-2021 04:28 PM - edited 01-24-2021 04:56 PM
Let's go with a description of one way for you to try coding it
You want a Generate Pulse.vi inputs Duration as I32 default 250, Surpress as BOOL required. Output Error Out as error cluster. Inside is a simple case Structure driven by Surpress TRUE does nothing and outputs no error, FALSE drives your hardware pulse for Duration in msec and outputs appropriate error if unsuccessful.
Main Vi Front panel controls numeric OFF Time as I32 in msec (I recommend a knob), BOOL, STOP button since that's a proper latching button.
Block diagram;
Create a while loop with 1 I32 Shift register initialized to -1 around both terminals
Create an Event Structure around both terminals ( that would be inside the while loop)
Wire the left side Shift register to the Event Timeout and OFF Time terminal back to the Right side Shift Register
Edit the events handled by the Timeout case adding OFF Time Mouse Up and STOP Value Change we only need one Event case.
After the event case drop Generate Pulse.vi and an OR .
Wire STOP to Surpress and an OR Input
Wire Error Out to the other OR Input
Wire OR output to the While loop conditional terminal
Drop a Simple Error Handler.vi after the While loop and wire Error out into its input
Document
Press run
This is not the only way to do this but, it's a great starter exercise for a beginner, easy to describe following good practices, scales nice, and I don't know what your hardware is. I've abstracted hardware in the subvi while seeing to the timing and UI needs you seemed concerned with.
BONUS there are all kinds of nice and easy things we can DO to it if requirements are clarified (changed) by the user
01-25-2021 08:34 AM - edited 01-25-2021 08:36 AM
This marked solution disappoints me. I would hope that the OP would post back with the coded solution for the benefit of other users.
I know that additional questions, tweaks, and comments from other posters COULD have made this thread a resource worth the effort I expended to set up that sample exercise.
I also think that the solution won't earn an "A" (ironically, its probably worth a "C+")
So, to the OP, come back for the learning opportunity.
01-25-2021 10:58 AM
I can see that I should be a bit more critical of my own decision making process before blasting out a help request. It's been 5 years since I did any LabVIEW work. Your words are taken to heart. The project is well in hand and I thank you for the help.
01-25-2021 11:18 AM - edited 01-25-2021 11:21 AM
andy.mcleod@unh.edu wrote:
I can see that I should be a bit more critical of my own decision making process before blasting out a help request. It's been 5 years since I did any LabVIEW work. Your words are taken to heart. The project is well in hand and I thank you for the help.
Not so much! It's just that time of year when homework request threads show up frequently. We try to get the students to do the work without discouraging them from critical thinking.
With a ".edu" in your alias you can understand why we suspected homework
Happy to have helped
01-25-2021 11:22 AM - edited 01-25-2021 11:42 AM
Here's what I came up with yesterday. Simple loop, no event structures or other complications.
(It would be easy to subtract 250ms from the off-times so the light flashes in exactly 1, 2, 5, or 10s intervals. It is also easy to start it with a flash instead of a wait. I probably would use a radiobutton control for the time selector. Note that the loop time should not be larger than the greatest common divisor of all wait times. The chart is just for illustration and can be deleted, of course)
See if this can give you some additional ideas.
01-25-2021 11:41 AM
@altenbach wrote:
I probably would use a radiobutton control for the time selector.
it could like that (same code!)
01-25-2021 01:04 PM - edited 01-25-2021 01:17 PM
@altenbach wrote:
@altenbach wrote:
I probably would use a radiobutton control for the time selector.
it could like that (same code!)
Hey, I did give myself a C+ for the exercise assuming a homework assignment. Do note that all those same questions/ improvements have nice places to hook up.
I am going to ask you though, .. how do you get the hardware back to default on FP Close without an event Structure? Yeah, that was an obvious easy add to the exercise:D. I do like the radio button as long as its set to allow exactly 1 selection ( a property hard to see in your code)
I imagine the A+ solution would have eventually been a QMH properly initializing and closing any resources.