How can I convert a 1D array with horizontal snake data to a vertical snake X and Y array?
Say you have a WxH matrix of 3x5 pixels. The 1D array of horizontal snake data would then be:
const uint8_t HorizSnake[] = { 0,1,2, 5,4,3, 6,7,8, 11,10,9, 12,13,14 };
And a vertical 3x5 would have data of:
const uint8_t XYVertical[] = {
0, 9, 10,
1, 8, 11,
2, 7, 12,
3, 6, 13,
4, 5, 14
};
for (int i=0; i<15; i++) {
leds[XYVertical] = leds[HorizSnake];
Does something like that work?
Mess with Garret Mace’s XY map generator to easily change your numbers around. Change horizontal/vertical, snake, starting points, etc as needed for your layout.
https://macetech.github.io/FastLED-XY-Map-Generator/
You want to have height and width from a 1d. Actually 1d and 2D are stored the same way.
To obtain a point at coordinates x.y =snake1d[x+y*width];
I now have this code https://pastebin.com/6g93HPzc I removed the read of serial for testing and only set led 1 to red. But when I run the code I get it not working
Is my loop okay? or is it wrong.
@Yves_BAZIN this only works for setups where each row has the same direction, doesn’t it? A “snake” alternates every row.