Pattern rule generation NeoMatrix

Yes that is a Left to right, bottom to top, row serpentine raster.

Raster.jpg

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.

Raster.jpg