06-07-2026 08:31 PM
I need a state machine with three steps. Each step has a Led. I need to turn on each led one after the other. And each led should be on for a given time period. I could be able to add the time period.
Thank you
06-08-2026 12:55 AM
Hi Rancat,
@Rancat wrote:
I need a state machine with three steps…
When you "need" code then you should create that code!
What have you tried?
Where are you stuck?
Which LabVIEW version do you use?
Have you tried to examine all the example code that comes with LabVIEW?
06-08-2026 08:58 AM
One way to build a State Machine is with a While Loop surrounding a Case Statement. You also need a variable (call it "State") that holds the particular State. What kind of variable do you want to use for State? [Since you are new to LabVIEW, you probably don't know about Enums, but you could use a String control (and "name" the States) or an integer (I8, since you probably will not need more than 100 different states, so you can call them 1, 2, 3, ...) for the State.
Do you know about Shift Registers (on the While Loop) which you will use to "hold" the value of the State when the While Loop starts, and updates it when the While Loop reaches its "right edge")? You initialize the Shift Register by writing the first State (1, or "Initialize" or "First State") to the left-hand Shift Register.
So now you put the Case Statement inside the While Loop and wire the "State" wire to the Case Selector, and carry this wire through the Case Statement, out the back end to the right Shift Register of the While Loop.
The Case Statement is where you put the code for each desired State. If you have variables you need to change, you place these variables on Shift Registers in the While Loop (which serves as the "memory" for that State) and do whatever processing of the variables is required by the State. If "timing" is involved (say, you want State 1 do increment a variable, wait 5 seconds, then go to State 2), you do all that programming within the State 1 Case. So you'd put an "Increment" on the Variable wire, add a 5 second (5000 ms) "Wait (ms)" delay, and increment the "State" wire (I'm assuming you are using an Integer "wire" for the State). So 5 seconds after you enter the Case Statement inside the While Loop, you'll exit it with the State incremented, and the While Loop will repeat (unless you wired "T" to the Stop control).
I've left out some steps (like how to initialize the Stop control), but you should be able to figure them out. Ask your fellow students, or your instructor.
Bob Schor
06-08-2026 09:06 AM
You can find examples and an explanation of a typical state machine at the LabVIEW wiki or the NI documentation.
06-08-2026 10:34 AM - edited 06-08-2026 11:02 AM
@Rancat wrote:
I need a state machine with three steps. Each step has a Led. I need to turn on each led one after the other. And each led should be on for a given time period. I could be able to add the time period.
From reading your question, you know what a state machine is and your program is almost complete except for the timing issue. Is this correct?
In that case, I would recommend to shows us your code draft (do a "save for previous", 2020 or below, because many don't have the newest version) and we will point you in the right direction.
As an example of simple state timing, have a look at my old traffic light example here. I am sure you can adapt it to your requirements once you understand the basic principle.
06-09-2026 02:32 PM
have you tried chat gpt ?