09-16-2015 07:20 PM
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.
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.
Any help will be appreciated.
Solved! Go to Solution.
09-16-2015 07:25 PM
What help do you need? Where are you stuck?
Is this homework?
09-16-2015 08:30 PM
Try this on for size.
09-16-2015 08:39 PM
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?
09-16-2015 08:47 PM
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.
09-16-2015 10:22 PM
@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! 😄
09-17-2015 01:15 AM
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! 😄
09-17-2015 10:21 AM
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.
09-17-2015 10:49 AM
@TWRLK wrote:
Is it possible to use just one loop and the replace array function?
Yes, of course. Try it! 😄
09-17-2015 04:50 PM
That's a beautiful VI altenbach, I could watch it all day...