Flowing aimation help

hi,
i'm using FASTLED library to show an animation,
and i'm showing currently on my led shades of specific color (pink in this example)
what i want it that animation to "flow"

meaning right now the darkest color is in 0 and the brightest is in 300.
i want it to flow meaning it will move up this pattern over and over again,
(like darkest color will be 1, brightest will be 0(because it will repeat itself), then darkest color will be 2 brightest will be 1... etc etc)

hope it makes sense
i tried multiple ways to achieve this and i fail every time

this is my function where i show the gradient

loop() {
    FastLED.show();  
    FastLED.delay(1000/FRAMES_PER_SECOND);
    gradientFlow();
}

void gradientFlow() { 
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CRGB( round (170+(i*0.26666)), 0, round (20+(i*0.26666)));  
    }
}

i tried passing an interval to the function and then move the darkest / lightest color based on that but that didn't work (this is what i tried >)

loop() {
    FastLED.show();  
    FastLED.delay(1000/FRAMES_PER_SECOND);
    gradientFlow();
}

int gradientInterval = o;
void gradientFlow() { 
    for( int i = gradientInterval ; i < NUM_LEDS; i++) {
        leds[i] = CRGB( round (170+((i-gradientInterval)*0.26666)), 0, round (20+((i-gradientInterval)*0.26666)));  
    }
    if (gradientInterval  < NUM_LEDS) {
        gradientInterval = gradientInterval  + 1;
    } 
}

which in my head would suppose to achieve what i wanted as every loop it will go there and start that "wave" from +1 led, and fix the colors appropriately

but it doesn't work i keep seeing the same pattern

i know it's hard to explain what i want hope it made some sense in here ?
any help in how to achieve this ? or what am i doing wrong ?

draw a picture or post a link to a video that shows what you want

Pass an 'offset' from 0 to 300 to move the starting point of the gradient:

void gradientFlow(int offset)
{
  for (int i = 0; i < NUM_LEDS; i++)
  {
    index = (i + offset) % 300;
    leds[index] = CRGB( round (170 + (i * 0.26666)), 0, round (20 + (i * 0.26666)));
  }
}

ok wow
so first of all it works!

but now i came into another problem (that can be another question but maybe if you solved that one you can also solve the second problem ?

so in short, it works, it makes the pattern repeate and it's all amazing
the problem is... that the pattern started from darkest, to lightest, so when it repeates it just looks wierd becaouse it causes it to be from lightest bolb... imidiatly to darkest one which looks bad

so i fixed it by making the "wave" or the "gradient" like go half the strip to brightest color
and go half the strip to darkest color
so the start bolb and end bolb are the same color now so if this will repeate it can be amazing

here is the code i did to achieve that

for (int i = 0; i < NUM_LEDS; i++){
      if (i < (NUM_LEDS/2)) {
        leds[i] = CRGB( round (170 + (i * 0.533333)), 0, round (20 + (i * 0.533333)));  
      } else {
        leds[i] = CRGB( round (330 - (i * 0.533333)), 0, round (180 - (i * 0.533333)));
      }
  }

but the issue now that if i add your fix it wouldn't work, becaouse it wouldn't know the num/2 anymore, and it all gets wierd...

Based on this updated code i showed in here
do you know of a way to achieve what i achieved before with your method
how to offset this one ?

Exactly the same way.

for (int i = 0; i < NUM_LEDS; i++){
      int index = (i + offset) % NUM_LEDS;
      if (i < (NUM_LEDS/2)) {
        leds[index] = CRGB( round (170 + (i * 0.533333)), 0, round (20 + (i * 0.533333)));  
      } else {
        leds[index] = CRGB( round (330 - (i * 0.533333)), 0, round (180 - (i * 0.533333)));
      }
  }
1 Like

you see that wouldn't work that's what I said...
because this line

if (i < (NUM_LEDS/2)) {

in original code is like... leds 0-150 go slowly to brightest
and less 150-300 go slowly to darkest

so that middle point will always be at 150
so even if you move the index, that middle point doesn't change

in any way my animation doesn't move if I do that copy pasted

Yes, and in the version that you said worked "leds 0-300 go slowly to brightest". That didn't prevent the offset from working. Are you not passing the offset anymore? Are you no changing the offset?

no I copy pasted same code
first time without that condition that from 0-150 it worked
and second time with that 0-150 and 150-300 it didn't work
I didn't do anything different just copy pasted

OK. Please show the entire new sketch that does not work.

wait...
i got it wrong
it DOES work
you were corerct i did something wrong with the index
OMG thank you so much this was amazing help !