I have a project that I would like to set up a logical led

I have a project that I would like to set up a logical led order that is different than the physical order.

Is there a way to end up with something like:

logical_leds[0]=leds[7]
logical_leds[NUM_LEDS]=leds[6]

I hope what I want makes sense, as to why, I think it would make using some of the wonderful patterns out there easier.

I’m not quite following yet but am curious to know more.

So you want to mirror the output?

I have two functions to copy the left to the right, and then the right to the left.

I’ll post them when I get home in an hour or so!

I think that is what I am asking I would like to use all of the standard FastLED features on logical_leds[] and have it mapped to the physical order in leds[]. I have been having problems translating some of Mark’s wonderful examples onto a shaped string that I want the patterns to start at a point that is not the physical start of the array, the wrap for the physical end of the array gets complicated.

You could have an int array for logical_leds, and then in functions you just get that position in the array and use it in leds[]

eg.
int logical_leds[] = {2,5,3,1,4,0};

and then if you wanted to use it in a loop
for( int i = 0; i < NUM_LEDS; i++) {
leds[logical_leds[i]] =
}

Not sure if this is the best way to go about it, but it should work.

If you want to use pointers to accomplish this, you could do:

int *logical_leds[NUM_LEDS];
logical_leds[0]=&leds[7];
logical_leds[NUM_LEDS]=&leds[6];

However this will use two bytes on the AVR, which isn’t efficient (the RGB data is already 3 bytes per pixel). @Chaka_September 's logical addressing using int indices has the same problem, but if you have <=256 LEDs, you could use unsigned char (aka uint8_t, which uses one byte) as the data type for the logical_leds[] array, and only use one extra byte per pixel.

If you can define it algorithmically, you might just want to define a function which translates the logical address to the pixel index:

int pixelForLogicalIndex(int logicalIndex) {
return NUM_LEDS - logicalIndex; // or whatever
}

This tradeoff will save you memory but cost CPU cycles. If you can define it mathematically in a preprocessor macro, you won’t spend memory, and the compiler will optimise anything that it can:

#define PIXEL_FOR_LOGICAL_INDEX(L) (NUM_LEDS - L)
leds[PIXEL_FOR_LOGICAL_INDEX(3)] = CRGB(255, 255, 0); // The compiler’s preprocessor will calculate (NUM_LEDS - 3) and substitute it here to avoid calculating it at runtime.

With your pointers example:

int *logical_leds[NUM_LEDS];
logical_leds[0]=&leds[7];
logical_leds[NUM_LEDS]=&leds[6];

I would continue this for each led either with a line for each or a loop, correct? I am working with 12 leds so it would not be difficult to have a line for each logical pixel.

To work with them I would just treat the logical_leds like the physical leds?

logical_led[0]= CHSV(77,255,128);

If so that would make the wrapping much simpler than what I am currently working with.

If you are interested in seeing the code I am currently using and is functional is here:

Thanks for the input and help.

To assign actual values to the address at a pointer, you need to dereference it like this:

*(logical_led[0])= CHSV(77,255,128); // You might not need the parentheses, not 100% sure about the precedence without a compiler handy

Ok, I will work on the development branch of my code and find out when I work on it later today. Thanks.

@Richard_Bailey I’m sorry I never got around to helping you further with this. I did have an idea that might help you simplify the code: rewire your LEDs. Because it’s a ‘B’, split it into 2 strips/2 data pins. I think you will find it easier to write code and come up with your own effects. What do you think about that?

If I build another one, I will split it into two segments. This one is already mounted and splitting it would be a major hastle.

I do this with my lighting boards for the R2 Builders. To keep the PCB’s compact my LEDs are wired “serpentine” style and in some cases are routed in a completely different order using fiber optics.

To control them, I start the sketch by defining a simple array that maps each LED’s final physical placement to its order in the circuit.

See this older sketch: Google Code Archive - Long-term storage for Google Code Project Hosting.
the rldMap array defines the LED’s placement, then I address each of the LED’s using (rldMap) instead of just (x).

I second the int array defining a new order. Ive done this plenty due to its simplicity, however the added memory consumption is a good point.

However I’ve been doing most of my development on the teensy 3.1 which relatively speaking has tons of memory.

Storing the int array in program memory will save a bit of RAM for you:

int logical_index[NUM_LEDS] PROGMEM = { 6, 5, 4, 128, 129, 130 };

On an ATMega328p there is 32kb of flash memory available.