LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I achieve this? read description below and see attached code.

Solved!
Go to solution

So I would like to make leds blink x amount of times based on my numeric value inputs. So let's say if my input is 2, the led should go ON and OFF 2 times, Input = 3>>>> Led = ON and OFF 3x, and so on.

 

The only time I am able to achieve blinking is when the input (numbers) are the same as shown below, but if for example, I input 8 and 7, there's no blinking. In brief, the only time there is blinking is when the inputs are the same. How do I fix this? I would like to achieve blinking when inputs are not the same as well. 

GRCK5000_0-1688137662184.png

 

 

0 Kudos
Message 1 of 7
(1,263 Views)

I won't give you the answer, but I will show you how troubleshoot it yourself.  On the block diagram, click the lightbulb to go into highlighted execution mode.  Then tell us why it isn't working.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 7
(1,245 Views)

Your code is full of glaring beginner mistakes.

 

  • Your "input number" control is outside the loop and will only get read once, Thus the values never change once the program runs.
  • Your "is value changed" primitive compares different elements in succession, for example it will tell you if the second element differs from the first element.
  • Why is your "input number" not just a plain integer array? Why the extra packaging into a cluster?
  • etc.
Message 3 of 7
(1,242 Views)
Solution
Accepted by topic author GRCK5000

See if this can give you some ideas....

 

altenbach_0-1688141922384.png

 

Message 4 of 7
(1,226 Views)

Thanks Mr. Altenbach for pinpointing what I was doing wrong. The modified code is exactly what I was trying to do. 

Thanks @Bilko, I really spent some time trying to find out what I was doing. I used that highlight execution. 

0 Kudos
Message 5 of 7
(1,203 Views)

@Mr.Altenbach! I have an after question for you. I'm over here trying to understand your code. It is great and that's exactly what I want to achieve. Thanks again! but I would like to understand what you did for self improvement or maybe someone else as well.

I'm running the code and place the probes as shown below. I input 100 for third led and the probe clearly reads "FALSE" as you can see below, but the counting keep going. How do you explain that? What's the logic behind it?

GRCK5000_0-1688145618864.png

GRCK5000_2-1688145818322.png

 

GRCK5000_1-1688145782571.png

 

 

0 Kudos
Message 6 of 7
(1,193 Views)

@GRCK5000 wrote:

What's the logic behind it?


Your FOR loops executes so fast that all you see is the value from the last iteration when the code pauses for 100ms before going to the next iteration of the while loop. All other probe values inside the FOR loop last only nanoseconds and there obviously is no way to see that. You could change the last of the controls to a high number and it should be mostly true when counting. Use execution highlighting to slow down the code if you want to debug the others. 

 

(Note that there is a tiny race condition, because if you change one of the controls, there is a small, but nonzero, probability that the change is undone when the local variable is written. See if you can fix that. 😄 )

0 Kudos
Message 7 of 7
(1,166 Views)