LED ordering, mirroring pattern one one strip of lights… How do?
Currently I’m building some controllers and running 2 strips from the controller which sits in the centre of the strips. The strips are wired to the same pin or are both receiving the same output to different pins.
What I would like to do is have the controller on one end of the strip and then have code handle mirroring the output from the centre of the strip outwards to mimic the effect I have building the controller in the centre of the strips.
Does that make sense? I can draw a quick diagram if helpful?
You can code patterns for just the first half and then call a function right before FastLED.show() that copies (and mirrors) that data to the other half. Lets say each “half” is 32 pixels, then something like:
#define NUM_LEDS 32 //pixels in one half
CRGB leds[NUM_LEDS * 2]; //total pixels for both strips
Code patterns as normal. For example:
fill_rainbow( leds, NUM_LEDS, millis()/20, 5);
or
for (uint8_t i=0; i < NUM_LEDS; i++) {
leds[i] = CHSV(random8(), 255, 255);
}
//Function to copy data to second half
mirror2ndHalf();
//Now display all the data
FastLED.show();
void mirror2ndHalf() {
// copy and reverse order to second half
for (uint8_t i = 0; i < NUM_LEDS; i++) {
leds[(NUM_LEDS * 2) -1 -i] = leds[i];
}
}
@Danny_Evans I just realized that the entire look of this new setup will be mirrored inside out vs the original setup. Assuming the first setup had the pixel data running from the center outwards, if you want your patterns to look exactly the same (with with data flowing from the center out) it will need to be slightly different then what I posted above.
Instead:
Code patterns as normal.
Then shift (translate) the position of the first half by NUM_LEDS.
for (uint8_t i=0; i < NUM_LEDS; i++) {
leds[i + NUM_LEDS] = leds[i];
}
THEN mirror the second half BACK to the first half.
for (uint8_t i = 0; i < NUM_LEDS; i++) {
leds[i] = leds[(NUM_LEDS * 2) -1 -i];
}
My first attempt at modifying some code to use this didn’t work out. I had only half the LED string light up.
But I’ll have another go tomorrow and post up what I do.
I’m really having a hard time understanding the syntax of the language. I can modify some variables in other’s code but writing it is still a way off for me.
I’ll try a couple of my favourite pieces of code from some FastLED gurus and see if I can modify them.
I think this is what you may be needing. If the controller is on one end and you want to mirror effects made on half a strip over to the other. With this and basic math you can just insert something like this line for a length of 144 leds.
leds[i] = leds[144-i]
Possible example:
void mirrorLED() {
for(int i = 0; i < NUM_LEDS; i++ ) {
leds[i] = leds[NUM_LEDS-i];
}
}
Colors can also be copied from one CRGB to another:
// Copy the CRGB color from one pixel to another
leds[i] = leds[j];
If you are copying a large number of colors from one (part of an) array to another, the standard library function memmove can be used to perform a bulk transfer; the CRGB object “is trivially copyable”.
// Copy ten led colors from leds[src … src+9] to leds[dest … dest+9]
memmove( &leds[dest], &leds[src], 10 * sizeof( CRGB) );
Performance-minded programmers using AVR/ATmega MCUs to move large number of colors in this way may wish to use the alternative “memmove8” library function, as it is measurably faster than the standard libc “memmove”.