09-10-2022 12:10 AM
I’m taking a university course where all assignments must be written in LabView. I’m new to this and we are expected to learn it on our own since the course does not give us any lessons in LabView. I’m currently working on an assignment that involves building a traffic lights simulator with different functionalities.
One functionality is an emergency switch that makes the yellow lights blink until the user flicks the switch again. I have tried to implement this functionality in a SubVI, but I’m struggling to understand how I can control the lights (LEDs) in the main VI from the SubVI. I would really appreciate it if someone can offer me some advice as I’m feeling very lost.
09-10-2022 12:17 AM - edited 09-10-2022 12:21 AM
There are learning resources at the top of the forum.
All you need is a simple state machine. No subvis at all.
See how far you get. If you get stuck show us what you have and ask specific questions.
09-10-2022 10:08 AM
Hi johnloser77,
I have attached a very simple light blinking VI (Example.vi) that you can use as an example to understand the basics, as well as expanding it for further functionalities.
As it has been said, you just need a simple state machine to make this work; no subVIs here.
Main points to consider in Example.vi:
- While loop makes the code execute continuously, so we can read the switch at each iteration, and output accordingly.
- Case structure has 2 cases: True and False. If the switch is True, True case will execute. And otherwise.
This post also deals with Traffic lights simulation: Solved: case structure: boolean control did not switch from false to true - NI Community
Take a look at this link, too: Application Design Patterns: State Machines - NI
We've all been lost at the beginning, make sure you take your time to understand the very basics.
Keep us updated!
Fort
09-10-2022 10:48 AM
Here's a simple example for one light (modified from here)
See if it can give you some ideas....
You can easily expand it to simulate a full intersection with multiple lights and such. Keep it simple!
09-10-2022 11:10 AM
If you are familiar with other programming languages (Basic, C/C++, Java, etc.), then LabVIEW will have a few "surprises" for you. Unlike (what I might call) "sequential" Languages, where you write down the steps "in order" that you execute them, sometimes "surrounding" them with other statements that represent a "boundary" that means "These are grouped together as one" (like a "Repeat .. Until" sequence, or a Function/Subroutine declaration, LabVIEW is a "Data Flow" language that has the following ideas:
On the Block Diagram Palette, the first item shows the common LabVIEW Structures, including For and While Loops and the Case Statement. The other Palette items are the more common Functions, arranged (more-or-less) by type of Data being processed (Numeric, Strings, Arrays, etc.). Sub-VIs that you write I can think of as "Functions" (because they "Do Something" to the Data).
Bob Schor
09-12-2022 04:37 AM
Hi Johnloser77,
as all the profis' reponses, the best solution is to make it as simple as possible, but if you insist to do data exchange between VIs, you can use FGV(Functional Global Variable), it is basically a VI you can use to save your data buffers and share between different structures and VIs. It has save the data in its Loop Shift Register.
https://learn-cf.ni.com/teach/riodevguide/code/rt_functional-global-variable.html
Regards,
FrankenChino
09-12-2022 10:41 AM
Let's go back to the beginning:
@johnloser77 wrote:
One functionality is an emergency switch that makes the yellow lights blink until the user flicks the switch again. I have tried to implement this functionality in a SubVI, but I’m struggling to understand how I can control the lights (LEDs) in the main VI from the SubVI. I would really appreciate it if someone can offer me some advice as I’m feeling very lost.
OK, so you say you want to implement the "functionality" in a subVI, but you even fail the mention where that "emergency switch" is. There are many possibilities:
90% of the correct solution is starting with a detailed definition of the problem. Maybe start by attaching the code you have so far.