Is there a way to reverse the order of LEDs without changing the code of the animation?
I am working on a LED Suit composed of 2 Neopixel strips of 60 pixels each, going to both sides of the upper body. For convenience, the strip are connected backwards, so I would like to draw the pixels in reverse order.
What approach would you recommend? Would you override the show() function or even the [x] operator of LEDController to write in reverse?
Using de map function of arduino an easy way to do it.
For example if you have a 120 led strip you can assing:
i=map(n,0,119,129,0);
Map will work, but it’s slow.
What I’ve done in the part is write a reverse function that (quickly) reverses a range of pixels. Then I do this:
…drawsrawdraw…
reverse(somepixels);
FastLED.show();
reverse(somepixels);
If I’m redrawing every pixel every frame, I don’t even need the second call to reverse(…);
I’ve used this in a case where wiring for one part of a structure made it easier to go backwards for one segment of pixels.
Ok, map isn’t SUPER slow, but it does involve a division operation which isn’t fast; I wouldn’t want to do a map for every time I update every pixel is all I’m saying.
@Mark_Kriegsman Thanks Mark! This sounds promising. Where can I find the implementation of the reverse function?
I’ll post an implementation later today if one hasn’t surfaced by then; a second array shouldn’t be needed. (Try googling for 'reverse an array of objects in C"; it’s a pretty standard first year computer science homework assignment, and thus should be all over the web.)
Right, thanks, I was looking for a way to avoid reversing the entire array for every show and back. I already have something similar to mirror the animation in the front and back: https://github.com/raphaelouzan/PowerLEDSuit
Yeah, I see that mirrorLeds() function, and it’d be nice to hide the physical layout from the logical array, but I think that a last-minute reversal is probably most compact and fastest.
what about modulo to reverse ? 0 % 60 = 60 etc …
To reverse you just use subtraction:
int revpos = MAX_POS - curpos;