Hello Guys,
I am working on a project where i want to create a pattern rule on a neomatrix such one of the LEDs on the first row (random) lights up and then next one should be two LEDS away on the x, y, x axis right or left for one of the patterns. And for the second patter the same thing but LEDs should light up in such a way there is a gap of three between them. Is there a way to do that? I am not very experienced with coding so i would really appreciate it if you can give me sample code or at least hints on how to do it.
Thank you!!!
two LEDS away on the x, y, x axis
That is not a matrix but a cube. Is that right?
Is there a way to do that?
Yes, there are several ways but first you have to know how things are wired up so that you can calculate an LED number from an x, y, z coordinate and back again, that is given an LED number get back a x, y, z coordinate.
Once you have those functions you can implement your rules us in either a look up table or algorithm.
i would really appreciate it if you can give me sample code
That normally means do it for you, unless you can give me an example where it would not be.
Hello Grumpy_Mike,
It is a matrix i just got it wrong by mistake. And sorry if it sounded like i want someone to write it for me. All i need is an explanation of how coordinates are defined because i find it hard to understand and how to use this to create a rule.
Thank you for replying!
Try googling "array stride"
But how is your matrix wired?
Is it a raster or a serpentine raster. That determines what you need to do to write those routines.
Draw it out, have the first LED, that is LED zero at the bottom left corner. Then write down the numbers of the LEDs as they would appear on the matrix, only do the first n x 3,where n is the size of the biggest side of the matrix.
Then I can show you how to work it out.
Grumpy_Mike, this is how they are arranged:
59, 58, 57, 56, 55, 54,
48, 49, 50, 51, 52, 53,
47, 46, 45, 44, 43, 42,
36, 37, 38, 39, 40, 41,
35, 34, 33, 32, 31, 30,
24, 25, 26, 27, 28, 29,
23, 22, 21, 20, 19, 18,
12, 13, 14, 15, 16, 17,
11, 10, 9, 8, 7, 6,
0, 1, 2, 3, 4, 5
So, serpentine.
Alternate rows reverse.
Yes that is a Left to right, bottom to top, row serpentine raster.
The conversion is:-
LedNumber = X + (Xmax * Y)
Given that X & Y are the coordinates we want to get the LED number for and Xmax is the number of LEDs in a row. Of course this assumes that both coordinates are within confines of the matrix. In practice it is necessary check the coordinates before calculating the LED number.
But the above conversion only works on odd numbered rows, for even numbered rows you need to use:-
LEDNumber = (Xmax - X - 1) + (Y * Xmax)
So any conversion routine must first test to see if the Y coordinate is indicating an odd or even row before choosing what formula to use. This is simply done by looking at the least significant bit of the Y coordinate.
int getLEDpos(int x, int y){ // for a serpentine raster int pos;
if(y & 0x1) { // is Y odd
pos = y * xMax + (xMax -1 - x) ;
}
else { // y is even
pos = y * yMax + x;
}
return pos; }
Where xMax is the number of LEDs in a row, and zero is considered even.