Hii, FastLED library is working just fine .I am stuck with some programming which

Hii, FastLED library is working just fine .I am stuck with some programming which i need help for.
My problem is with the function named " void FillLEDsFromPaletteColors( unsigned char colorIndex) " which is used in the example that is included in the FastLED library called " colorpalettes ".
the function mentioned above assigns colorIndex +=3 on the last line of the function, It controls the direction of color flow(THIS IS WHAT I UNDERSTAND) i.e when colorIndex +=3 is assigned color direction is from 50 (NUM_LED) towards 1(First LED) & when colorIndex -=3 is assigned color direction is from 1st LED towards 50 (NUM_LED).
NOW, what i need to do is to change the direction successively.
Thank you for your time and help.
Below is the Function where colorIndex is assigned

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;

for( int i = 0; i < NUM_LEDS; i++) {
    leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
    colorIndex += 3;
}

}

THANKS

If I understand what you want to do, you’d like to be able to change the direction on the fly? Here’s one way to do it.

Create/add a new variable in the top section of the program, let’s call it dir (for direction):
int8_t dir = 1; //direction. [will be either 1 or -1]

Inside the main void loop() add this to toggle it from 1 to -1 at what ever rate you would like:

EVERY_N_SECONDS(2) { // change direction every few seconds
dir = dir * -1;
}

Remember that: colorIndex +=3;
is the same as: colorIndex = colorIndex + 3;

Rewrite that line adding the dir variable as a multiplier:
//colorIndex += 3;
colorIndex = colorIndex + (3 * dir); //updated with dir

You could also make the “3” a variable of some sort to be able to have even more visual changes.

@marmil Thanks you very much for your help and Quick reply.

Is it possible to move colors Inwards towards the center as well as out wards from the center LED.

Yes, instead of filling the whole strip, just fill half (NUM_LEDS/2) and then use a for loop to copy those pixels to the other half before calling show(). Changing dir would then cause the flow to be inward or outward.

Hmmm I will try this one. It might take some time as i am new to programming. thank you very much

We all start somewhere and these are the best sort of exercises to keep learning. Also look at as many examples as you can to find to see how others manipulate things. And copy those examples and mess with a few variables or lines of code at a time to see how it changes the output.

oh ya thanks for the advice

@marmil Hii,
I have a question,how to do the copy thing using for loop that you mentioned earlier is there any example related to it.I tried but could not get the desired output

This would make the second pixel equal to the first.
leds[1] = leds[0];

This would make the last pixel equal to the first.
leds[NUM_LEDS-1] = leds[0];

Using a for loop, you can copy a bunch of pixel data to other pixels.

This copies the pixels from the first half of the strip to the pixels in the second half of the strip, and also reversed the order (copying to last pixel and then back toward the middle) at the same time.
for (uint8_t i = 0; i < NUM_LEDS/2; i++) {
leds[NUM_LEDS-1-i] = leds[i];
}

Here’s another variation of using a loop to copy pixel data from one pixel to another. In this case it’s being used to move (shift) all the data down the strip by one position. It starts at the end and works back toward the beginning of the strip.
for (uint8_t i = NUM_LEDS-1; i > 0; i–) {
leds[i] = leds[i-1]; // shift data down the line by one pixel
}

Step through the above examples on paper if needed to make sure you see how it works. Once you understand it you will think of fun ways to use something like this in your patterns.

I did some thing similar but now let me figure out what i did wrong.
Any ways thanks.

I just figured it out, and now its working as desired.
you have been a great help.