Say I wanted to shift the RGB of each LED up one LED and

Say I wanted to shift the RGB of each LED up one LED and have the last one wrap around to 0 like a circular shift array. The best way I know of to do so is to create another index to the array and have functions take care of wrapping the index. The problem that I am having is that I can’t figure out how to do so. It seems like I would need to pass; an index number so it could run from there instead of 0. Sorry if this is a dumb question but I’ve spent quite a bit of time with dear old Google and the source files to no avail.

So the question is, what’s the best way to accomplish shifting the values of each LED up one LED?

The library doesn’t do that kind of wrapping around an array - at least not at the level of show - a variety of reasons for that.

You could do it this way, though:

// save the first element
CRGB first = leds[0];
// shift every element down one
for(int i = 1; i < NUM_LEDS; i++) { leds[i-1] = leds[i]; }
// put the first element in the last slot
leds[NUM_LEDS-1] = first;

I’m still giving thought to designing a ‘container’ for a group of leds with a variety of functions for transforming/re-arranging leds and such. It is unlikely that we’ll have something for this version of the library, though

Alas… so the next best option to achieve that kind of effect would be to memcopy on the leds[]? Is that approach reasonable?

or memmove rather…

Basically yeah - there are a bunch of the things that the library does at a low level that the overhead of doing this kind of rotation during writing the data out would cause problems with some of the chipsets that are being used.

One thing I have some code playing with is using the DMA subsystem to make these operations faster when running on systems that have them, but it is nowhere near ready for other people to play with.

Cool. Thanks. :slight_smile:

On AVR, memmove8 from FastSPI_LED2 is faster than the standard library memmove. (And this is one of the reasons why this library is “fast”: it’s not just that it’s exceedingly fast driving the LEDs. It also gives you a collection of high performance support functions to make your project fast.)