LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Turn LED ON (1 second) and OFF (9 seconds). Code modification trouble!!!

You're definitely right. Now, you know exactly what I'm talking. Thanks! This will make it clear for others. I'm working on the math and will post what I get. I've been struggling a little bit, but what you had 3*2.65 = 7.95 kind of gave me an idea.

0 Kudos
Message 11 of 40
(869 Views)

Hi Mr. Altenbach,

sorry for messing your code up haha.

But would you please refer to my conversation with GERDW? He knows exactly what I'm trying to achieve.

0 Kudos
Message 12 of 40
(865 Views)

Hi GerdW,

What do you think about what I have now? see attached code. It kind of seems like it's working, but I am still not sure if each relay is being off for 9 seconds. I tried using my phone timer, it seems like they are being turned off for a little bit more than 9 seconds. but it looks okay to me. Feel free to share any knowledge or better way to do it. I'm here to learn. There is always room for more knowledge.

Hopefully, this code brings more clarification on what I am trying to achieve.

0 Kudos
Message 13 of 40
(855 Views)

@GRCK5000 --

 

Your title is wrong!  You don't need "Code modification", you need to simply read (tutorial material, LabVIEW books, though I don't have one in mind to recommend, the training material mentioned at the beginning of this Forum), pay attention to what you read, don't skip, do simple things before doing complicated things, and PLAN.

 

Consider the statement of your Problem.  Turn LED On (for 1 second), then off (for 9 seconds).  You don't say, but presumably "and repeat until I push the Stop button".

 

OK.  A Quiz:

  • How do you turn an LED On?  How do you wait for 1 second after you turn the LED On?
  • How do you turn an LED Off?  How do you wait for 9 seconds after you turn the LED Off?
  • Suppose that was all you wanted to do -- turn on for 1 second and turn off for 9 seconds, then stop the program.  How would you do that?
  • [Hmm -- I just simplified the code that I wrote to do this, because I left out the first two steps.  You can learn something by going slowly and methodically!]
  • OK, now how do you do something over-and-over again until it is time to stop?

Write these steps down "in your head", but do not put them on a Block Diagram (yet).  Open LabVIEW.  Open the Timing Palette.  Do you see a function (maybe in the upper-right corner) called "Stall Data Flow.vim"?  Read the Detailed Help associated with this function.

 

I am deliberately NOT including the (almost trivial) code that I wrote.  Please indulge me and take the simple Quiz I provided to you -- it will, I hope, get you to start thinking "WHAT do I want to do", instead of "How can I use the limited things that I have learned, without considering if they are appropriate to my problem, but can make a very involved VI that convinces people I know what I'm doing".  Good LabVIEW code is often Simple LabVIEW code.

 

Bob Schor

P.S. -- I'll post my VI in a day or so, unless you follow my suggestion to "take the quiz" and figure out the Much Better Way (IMHO) to solve your problem yourself.

 

 

0 Kudos
Message 14 of 40
(838 Views)

I personally would achieve this with a simple state machine or flat sequence structure. My code would be completely different from Mr. Altenbach's code. My code would be probably extremely large. He is able to do this using a single small while loop. It's just unbelievable.

0 Kudos
Message 15 of 40
(831 Views)

Again, you completely butchered my earlier code. See if this can give you some ideas....

 

altenbach_0-1674172704703.png

 

 

(... and Please (!!!) don't maximize the front panel to the screen. That's just annoying!)

0 Kudos
Message 16 of 40
(818 Views)

But state machine is my favorite tool. I'll probably change my name to "TheStateMachineMaster" 😂

0 Kudos
Message 17 of 40
(816 Views)

Mine IS a state machine in the general sense!

0 Kudos
Message 18 of 40
(811 Views)

Thanks Mr. Altenbach! From the code you attached it seems like each LED is being off for more than 9 seconds. In 1 complete cycle, I would like each LED to be OFF for 9 seconds.

For example, when you run the program. The flow goes like LED 1> ON OFF, LED 2 > ON OFF, LED > ON OFF, LED 4 > ON OFF = 1 cycle.

So 1 cycle is complete when the 4th LED turns OFF. So in 1 complete cycle, each LED should be OFF for 9 seconds and ON for 1 second. 1 complete cycle should equal to 10 seconds I believe.

I think the problem is with my wording. 😔

0 Kudos
Message 19 of 40
(809 Views)

Of course the LEDs will also be off if it is not the current led. You can't have both.

Do you mean that after 10 second #1 and #2 should be on? At the end all should be on?

 

If each led should have its own timing, you need to maintain an array of times. Easy to do with minimal changes.

0 Kudos
Message 20 of 40
(805 Views)