How to setup LED reference struct

Status
Not open for further replies.

Steve01

Active member
I am wanting to map my LED layout in a linear fashion even though it isn't. I can use a 'struct' but was wondering if anyone has a better idea. I want to wire my LEDs in a zig-zag pattern so that in the future I can use the VideoDisplay sketch but for now I'm just sending color data to each LED.

For example:
I have 150 LEDs in a strand but they zig-zag.
0 - 49
99 - 50
100 - 149

I want to map them so that they are referenced to me in a linear fashion. 0 - 49 99 - 50 100 - 149 would look to me like 0 - 149.

I could use

struct LEDs
{
byte led0 = 0;
byte led1 = 1;
//and so on
byte led99 = 50;
byte led100 = 51;
}

I want to use the OctoWS2811 library to with this so I need to be able to iterate through the struct.

Is there a better way than a 'struct'? I was hoping something that doesn't use so much memory.

Thanks in advance,
Steve
 
Well, I solved my own problem by just using an Array. I was thinking there would be a better way do do it precompile but the array works just fine.
Here is an example if someone else wants to do it this way.

int LED[] = {0,1,2,3,4,5,6,7,8,9,19,18,17,16,15,14,13,12,11,10,20,21,22,23,24,25,26,27,28,29};
So when you get to the LED[10] it actually is '19'.
 
Roughly, you want something like the below - then you can just access led pixels by x/y locations without eating up a bunch of ram for the array.

#define NUM_LEDS_PER_STRIP 50
#define ZIGZAG 1

int xy(int x, int y) {
if(ZIGZAG && y & 0x01) { return (y * NUM_LEDS_PER_STRIP) + ((NUM_LEDS_PER_STRIP - 1) - x); }
else { return (y * NUM_LEDS_PER_STRIP) + x; }
}
 
I was thinking about adding some iterator facade trickery, but then again I don't know if the octo library would make use of it.
 
Status
Not open for further replies.
Back
Top