LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How I can manipulate a 2D array of leds so that the LEDs light up in different ways ?

Solved!
Go to solution

Hello everyone. I hope someone can help me. 

 

I have a 2d array of leds of dimension 4x4. I want the leds light up in two different ways.

 

The first one, I want the leds to light up from left to right. In the followinf order:

0,0  0,1  0,2  0,3

1,3  2,3  3,3

3,2  3,1  3,0

2,0  1,0  1,1  1,2  2,2 and 2,1 

So in the end the whole array is lit. 

 

imagen1.png

 

The second one, I want the leds to light up from right to left. In the following order order:

0,3  0,2  0,1  0,0

1,0  2,0  3,0

3,1  3,2  3,3  2,3  1,3

1,2  1,1  2,1 and 2,2

So in the end the whole array is lit. 

 

imagen2.png

 

Any help will be appreciated.

 

 

 

 

 

 

 

 

0 Kudos
Message 1 of 16
(6,641 Views)

What help do you need?  Where are you stuck?

 

Is this homework?

0 Kudos
Message 2 of 16
(6,636 Views)

Try this on for size.

 

test.png

0 Kudos
Message 3 of 16
(6,610 Views)

Hi, thanks for answering. I have made a 1D array of Leds to light up in different ways without problems. But a 2D array with nested for loops I get lost.

Can anyone help at least with one of this, so I can understand how the loops work with indexing?

0 Kudos
Message 4 of 16
(6,602 Views)

A 2-D array wouldn be much different than a 1-D array.

 

Have your data that you pass in at each step be a cluster of two integers, one representing column, the other the row.  Pass an array of each step into a For Loop

 

At each step of the loop do a Replace Array subset on your 2-D array of LED's with a True value where the integers in the cluster are wired to the indices of the Replace array subset function.

0 Kudos
Message 5 of 16
(6,595 Views)

@B_Strange wrote:

Try this on for size.


This is not a scalable solution, because it cannot easily be expanded for larger array sizes and becomes quickly unmanageable. I would stay away from any explicitly and tediously constructed relatively mindless code.

 

As Raven already hinted, all you need is a single loop and a 2D boolean array in a shift register and you turn elements ON by using "replace array subset". Make it as a state machine, one state for a clockwise spiral, one for turning all off, and one for a counterclickwise spiral.

 

You can create a tedious list of indices in the desired order, and start from scratch whenever the desired array size changes or you could make a fully scalable solution. After all, the lighting rules can be basically described in a few words, so implementing it in LabVIEW code will be equally easy.

 

One possibility would be to make the 2D array larger by two rows and two columns and make all border elements true, hide them by setting the container index to 1,1, then hide the index terminal, and resize the container to hide these border elements. Now all you need to do is start from a certain element in a given direction, lighting elements as you go, and turn right by 90 degrees whenever the prospecive next element straight ahead is already true. Once all surrounding elements are TRUE, we go to the next state and set the array to the starting values, then do the other direction, etc.

 

There are many other possible algorithm to determine the lighting order without having to create a long list. We are programmers, not bureaucrats! 😄

 

 

 

0 Kudos
Message 6 of 16
(6,567 Views)

Another useful skill is searching the forum. You might have found this post. A few trivial modification would give you a fully scalable solution that works without changes for any size rectangular array.

 

Here's what I came up with in a few minutes.

 

Be warned that you cannot turn this in as homework unless you fully understand every single detail of the program (For example you need to understand multiplication of complex numbers!)

 

Your teacher reads these forums too! 😄

Message 7 of 16
(6,544 Views)

Wow man, you are a pro. I will try to understand your code alone since I am a self taught and I do not have a techer. BTW is there a way to put the two ways in two different arrays? Is it possible to use just one loop and the replace array function?

 

Thank you.

 

0 Kudos
Message 8 of 16
(6,500 Views)

@TWRLK wrote:

Is it possible to use just one loop and the replace array function?

 


Yes, of course. Try it! 😄

0 Kudos
Message 9 of 16
(6,481 Views)

That's a beautiful VI altenbach, I could watch it all day...

0 Kudos
Message 10 of 16
(6,447 Views)