06-17-2010 09:17 AM
I'm looking for some advice on the best practice to structure this type of operation...
I have a main vi that allows the user to select an LED to illuminate (physical LEDs, not virtual). This will work by the main vi calling a sub vi that is responsible for controlling the LEDs.
I want the LEDs to operate in the following method:
1. User selects LED to turn on...that LED turns on
2. LED will turn itself off (timeout) if a period of time passes (time set by user in main vi)
3. If user selects a different LED to illumininate, the previous LED will shut off, and the selected LED will turn on. I want this to happen even if the timeout of the previous LED hasn't occured yet.
4. Timer resets
5. Rinse and repeat 🙂
Thanks! -Mike
06-17-2010 09:27 AM - edited 06-17-2010 09:29 AM
If you are using a version of LabVIEW with event structures I would put the LED selection in one loop, the actual LED control in a parallel loop, communcating via queues or functional globals, in a "produceer/consumer" style (look at the built in LabVIEW examples). Then the vi controlling the physical LED can keep track of the timeout, etc. I don't know how you are controlling the LED's, a digital output? The actual controlling vi would probably be a state machine that has states for changing the on/off state of the LED, keeping track of the timeout for the currently on LED, etc.
06-17-2010 09:33 AM - edited 06-17-2010 09:35 AM
I'm using LV2009, so yes, I have access to event structures...
Are you saying the main vi would have two parallel while loops?
The main vi output a number, which correpsonds to an LED...
I'll start on the state machine. Anyone know of any examples like this?
-Mike
06-17-2010 10:34 AM
06-17-2010 11:33 AM
06-17-2010 11:44 AM
06-17-2010 11:53 AM
If you post your code and explain your problem, I'll be glad to help.
06-17-2010 12:06 PM - edited 06-17-2010 12:10 PM
tbob wrote:
Don't use the wait function. Use the Elapsed Time function. Put it in a loop. Use an OR fucntion to stop the loop. Stop the loop when either the Elapsed Time has expired OR the user presses a button that is supposed to override the timer.
Another great use for the elapsed timer function! But you could improve the code just a bit (to add expandtion capabilities) by adding a third loop and a second queue!
I'll post a mock-up in a bit- but I'm thinking a UI loop- firing event driven commands to two consumers> an LED control (simply runs the hardware task) and a timer control loop (start timer- reset timer. this loop would also enqueue a command for the LED control loop on a when timer expires.- and you CAN use the TIMEOUT event wnd move the timeout value by adding the timmeout value as a component of the queue
Neat?
06-17-2010 12:32 PM
06-17-2010 04:52 PM
And - just for fun a completed example- just replace the task!
Odd- when creating a snippet the cluster elements are deleted! so no snippet