LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Blinking led using a state machine

I need to blink a led two times and then turn off, after the second led has to do the same, I'm using a case structure and shift registers but it only stays in first case, I need to do this change automatically,  this is my VI, thanks 🙂

0 Kudos
Message 1 of 11
(6,533 Views)

You should also include counter to count led blinking. Make generic program using comparison with count with respect to count achieved by led blink.

 

Make program like: IF LED BLINKS, COUNTER++, COMPARE WITH COUNT, MAKE DECISION BASED ON COUNT RESULT TO SWITCH CASE FOR ANOTHER LED

 

Regards, 

DCKAN


Best Regards,
DCKAN

"We make a Living by what we get. We make a Life by what we give."
0 Kudos
Message 2 of 11
(6,522 Views)

Did you mean something like this?

 

0 Kudos
Message 3 of 11
(6,478 Views)

Think about the problem you stated.  Let me suggest one way to break it down:

  • You want to "blink" an LED.
  • You want to have a sequence of Blinks for a number of LEDs.

First question -- how do you "blink" an LED?  What does this mean?

Second question -- do you know how to "generalize" the first question so you can "plug in" the LED you want to blink?

Third question -- if you can answer the second question, how would you use this solution to come up with "Blink a specific LED a specific number of times"?

 

I'm uncertain how much LabVIEW experience you have.  I, myself, am a Great Believer in sub-VIs.  In particular, I would write a "Blink" sub-VI that has two parameters, a reference to the LED I wanted to blink and the blink On/Off Time.  I might also "have my cake and eat it too", and include a third parameter, the number of blinks.  The key "advanced topic" here is the ability to pass a reference to the Front Panel LED indicator, so that one sub-VI can do the work for any particular LED.

 

If you know about sub-VIs and using references, your problem becomes very simple -- Call Blink with a reference to LED1, a Blink On/Off Time, and the number of blinks, 2.  Follow this (using the Error Line, which you should always put in the lower left/right corners of all of your sub-VIs, to connect to the first call to Blink) another call with LED2 and the same parameters.  Voilà.

 

Suppose you don't know about sub-VIs?  Well, start by thinking about how you would code Blink if you had the LED indicator available as well as the Blink On/Off Time and number of blinks.

 

How would you make a single Blink, given an indicator (LED1, say) and a Blink On/Off Time (I'm going to assume that if this is 1000, this means "turn on for 1000 msec, then turn off for 1000 msec, then we are done").  Hint -- you can do this several ways, but one is with a For loop that counts to 2 (the "on" + "off" states), a Boolean Shiift Register, your LED indicator, and a Time function.

 

So now what do you have to do to this simple "blink" to make it do multiple blinks (controlled by a Number of Blinks control)?

 

Once you have this worked out, i.e. how to make one LED blink as specified, figure out how to do the same thing for the second LED.  The code should look very similar -- the main issue here is how you sequence the two sets of actions.  There are multiple ways to do this, including stringing them along in a sequence (having an Error Line helps to "sequentialize" things) or putting them in a loop and choosing which alternative to do.

 

Bob Schor

 

0 Kudos
Message 4 of 11
(6,393 Views)

P.S. -- your title mentioned a State Machine, which implies a loop + Case Statement to "do the right thing".  There are multiple SMs you could construct here, of multiple granularity.  Think about making the Blinker (which does a single Blink) a State Machine -- what States would it need?  One possibility would be a three-State machine -- Start, Blink, and Stop.  You could also build a higher-level State Machine that has three States -- Blink LED1 Twice, Blink LED2 Twice, and Quit.

 

Can you code these?  Do you know about Enums (to define the States), While Loops, Shift Registers, and Case Statements?

 

BS

0 Kudos
Message 5 of 11
(6,386 Views)

It is some sort of school project assignment.

 

He has a duplicate thread in Spanish http://forums.ni.com/t5/Discusiones-sobre-Productos-NI/Encender-un-LED-con-m%C3%A1quina-de-estados/m...

and there are replies

 

 

0 Kudos
Message 6 of 11
(6,369 Views)

If he has two LEDs he wants to blink sequentially and this is a homework assignment, it's designed to be built showing how states transition.  Three states becomes a bad idea at that point.  You'll want states to blink to show the transitions.  Once you start getting more complex with blinking subVIs, you're gettig away from the idea of a state machine and further from the assignment.

0 Kudos
Message 7 of 11
(6,346 Views)

It really would be so much easier for us to do students' Homework if they would just post the Homework Assignment.  If they also include the Instructor's e-mail address, we could send the solutions directly to the teacher ...  Sigh.

 

BS

0 Kudos
Message 8 of 11
(6,329 Views)

And, sometimes, we could even teach the instructors a little about LabVIEW.

 

Lynn

Message 9 of 11
(6,272 Views)

?

0 Kudos
Message 10 of 11
(6,223 Views)