LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble using case selector inside a for loop. Please help.

I am having a real hard time getting this to work. Im new to Labview, and it has not been too pleasant so far.  I need this VI to light a Boolean LED (true)  that corresponds to the appropriate digit chosen on the front panel array.  The way I have it, it only works when the specific number of the element is chosen.  So if element 0 is 0, it will light the 0 led.  However, it will not light any of the other leds.  Element 1 of the array will only light led 1, and it will not light any other led in the array.  This continues from array element 0-7.  Any help would be appreciated, as I am frustrated at this point.  Thank you ahead of time.

0 Kudos
Message 1 of 8
(3,259 Views)

I do not understand what you want.  The VI you posted will match array elements to LEDs where the LED number equals the array index value and the element at that index also has that value.

 

I suspect that is not what you want.  Please post again with some examples.  Tell us what the values in the array are and which LEDs should be on for each value.

 

Several comments about your VI:

1. When using autoindexing in a for loop, do not wire a value to N. The length of the array sets the number of iterations of the loop.

2. For the values you are using the case structure is not needed.  Simpy compare the array value to "i".

3. You do not need to convert the boolean array to a cluster and then unbundle it.  Just use Index Array and expand it to return all the elements.

 

The image below shows 2 and 3 and produces the same result.

 

Kmap3.png

 

Lynn

 

 

0 Kudos
Message 2 of 8
(3,248 Views)

That's because you wired your i loop iteration value to the case structure selector.  Try wiring the value coming from the array.  Then you won't need to do a comparison to 0 or 1 or 2 or ....   You just wire out a true constant.

 

By the way, going from a boolean array to a cluster then unbundling that cluster is a Rube Goldberg .  You should be using Index Array to break apart the boolean array like you did in the lower half.

0 Kudos
Message 3 of 8
(3,247 Views)

Lynn,

 

Thanks for your input. No, the VI is not doing what i want. Im having a hard time explaining what it needs to do.  Here are some examples.

 

On the front panel:

Say that array element #0 has a numeric value of 1, LED # 1 will turn on.

Say that array element #1 has a numeric value of 2, LED # 2 will turn on.

Say that array element #2 has a numeric value of 3, LED # 3 will turn on.

Say that array element #3 has a numeric value of 5, LED # 5 will turn on.

Say that array element #4 has a numeric value of 6, LED # 6 will light up.

Say that array element #5 has a numeric value of 0, LED #0 will already be on because it was chosen at array element #0.

Say that array element #6 has a numeric value of 0, LED #0 will already be on because it was chosen at array element #0.

Say that array element #7 has a numeric value of 0, LED #0 will already be on because it was chosen at array element #0.

 

I hope this perhaps makes it simpler.

 

0 Kudos
Message 4 of 8
(3,241 Views)

You will need to maintain the array of booleans in a shift register withing the For Loop.  Use Replace Array Subset to replace a particular boolean at an index with a True.

0 Kudos
Message 5 of 8
(3,237 Views)
Message 6 of 8
(3,226 Views)

This definetely works.  Was mine really off? Im just starting to use labview, and it seems more confusing to me than C++.  Is there anyway to get mine working like the code you posted without too many modifications? Or was I completely off?

0 Kudos
Message 7 of 8
(3,191 Views)

You were completely off. 😉

0 Kudos
Message 8 of 8
(3,182 Views)