12-03-2024 09:54 AM
Hey there,
I'm relatively new to the world of LabVIEW and currently struggling to work out my homework task.
The task was the following:
I figured out how to implement mode 1 and 2 (I will add a link to the project) but I don't know how to mode 3.
Here's what I currently got:
I embedded the whole code in a producer/consumer structure.
Right now, LED1 is flashing 5 times before LED2 flashes one time, then it gets back to LED1 flashing. I know that this is because of the way I defined the inner case structure.
Is the approach with the inner case structure valid?
I will probably need another array but right now I'm pretty much stuck, so I'm thankful for any kind of help!
I am working on Labview 2021.
12-03-2024 10:14 AM - edited 12-03-2024 11:08 AM
This is a very simple task and you have way too much code for such a simple problem. All you need is a simple state machine running at a constant rate that changes state as a function of elapsed time and mode.
I'll have a look....
12-03-2024 11:07 AM
See if this can give you some ideas....
Note that the loop spins at a constant 50ms and changes state as a function of accumulated time. This is especially useful for longer time delays that would interfere with responsiveness. You want to read the controls often, even if the delay is 30 seconds.
(of course your teacher reads this forum too, so make sure you fully understand the logic, then apply selected ideas to your code. Be creative!)
12-04-2024 09:18 AM
Hi altenbach,
thank you very much for taking the time and designing the code!
There are definitely some ideas which i will use, e.g. the clustering and using more of "or"/"and" logic.
However, i think my original message might have been somewhat misleading. The mode "flash 5 times" does not refer to all LEDs flashing simultaneously for only 5 times. It was rather supposed to look like this: The first LED flashes 5 times while all other LEDs are off. Then the second LED flashes 5 times and so on. All this going on indefinitely.
I am pretty sure that I can make this work with "replace array subset" but it still really throws me off...
And concerning my prof: He will for sure be around the forum from time to time but the homework is voluntary and not graded. So this should not be a problem 🙂
12-04-2024 09:51 AM
Yes, I did not read the description in detail, but your "5" mode would only requite some very minor changes to implement, It is just a longer cycle with otherwise very similar logic. (It is actually simpler than the current 5 flash cycle). Try it!
You could actually add many more flashing modes by just adding items to the enum and adding more cases. Scalability is always good!
12-05-2024 09:11 AM
I spent some more time and I finally figured it out! It may not look as clean as your solution but for now, I am happy with it.
If you still have some spare time, could you have a look at my solution now and see if you still have any tips for further improvement? (In LEDs_one_loop I got rid of the producer-consumer structure)
Anyways, thanks a dozen again!!
12-05-2024 11:19 AM
Sorry, I only have LabVIEW 2020 at the moment so I cannot look at your VI, but here's one possibility:
12-05-2024 12:07 PM - edited 12-05-2024 12:08 PM
Also note that if the patterns are relatively short, but complicated, a LUT (lookup table) would allow a solution with basically no fancy logic. (here the third pattern is some kind of zig-zag). It is now easy to add any other pattern graphically by adding elements to the diagram constant and items to the enum without any other changes in the code.
12-05-2024 01:30 PM
@jonask99 wrote:
If you still have some spare time, could you have a look at my solution now and see if you still have any tips for further improvement? (In LEDs_one_loop I got rid of the producer-consumer structure)
Anyways, thanks a dozen again!!
Here's just the tip of the iceberg:
12-09-2024 07:42 AM
- Your wait should be U32, not I32 (notice the coercion dot?). It is typically a really bad idea to slow the loop. For example if you do a 10 second delay, the VI might take up to 10 seconds to react to the OK button. It is significantly better to keep track of elapsed state time as I did. Do you understand my code? (If you want to keep the current code, set the data entry to not allow more than 1000ms or less. Currently, the user can enter 2147483647ms and nothing will ever happen, even if you set it back to 500ms while the program is running.
I understand the principle idea of the constant 50 ms wait and the separate delay. However, I do not fully understand the feedback node construction. Could you please explain what is going on there?