FastLED Cylon need help

Hello guys I'm new here, I have been working on cylon effect under fastLED example and I have decided to split the effect in the middle but when I run the code it doesn't work as intended. One side works fine and the other is very slow. is there wrong with the code?

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loop() {
static uint8_t hue = 0;
for(int a = 9; a >= 0; a--) {
    for(int x = 11; x < NUM_LEDS; x++) {
    leds[a] = CHSV(hue++, 255, 255);
    leds[x] = CHSV(hue++, 255, 255);
    FastLED.show(); 
    fadeall();
    delay(30);
  }  
  }
  }

Your code executes the inner for loop 9 times.
Is that deliberate ?

It looks to me as though you only need one for loop inside of which LEDs in both ranges are controlled at the same time

I'm sorry I'm not quite good at for loops I thought that loop A is for assigning leds 1 to 9 and loop X is for the rest... Do you have an idea how how to put these ranges in one for loop?

Apparently when I run the code the lights are not sychronized.. I've spent hours figuring it out but I still have no idea

Do you have an idea how how to put these ranges in one for loop?

Yes, if you want the effect that I think you do

Please start by explaining what order the LEDs should light up/turn off in and how many of them there are

Just 21 leds
The light runs like this
<<<<<<11th>>>>>
|1-10| |12-21|

the 11th is just black, the color is just the same as the previous code. Changing color as its runs and it fade a little before the next wave of color.

Let's get them in the right order before adding other effects
I am presuming that the LEDs come on in pairs like this
10 and 12
9 and 13
8 and 14
and so on

Start by trying this

void setup()
{
  Serial.begin(115200);
  while (!Serial);
}

void loop()
{
  byte offset = 2;
  for (int x = 10; x >= 0; x--)
  {
    Serial.print(x);
    Serial.print("\t"); //tab
    Serial.println(x + offset);
    delay(1000);
    offset = offset + 2;
  }
  Serial.println();
}

If the LED numbers are correct when viewed in the Serial monitor then apply the principle to your code to turn on the pairs of LEDs. When should the LEDs be turned off ?

Yes something like that.. I tried the code but I got an increment results:

10/t12
11/t15
12/t18
13/t21

The led is to be used as hazzard light on a motorcycle so it should have a switch to turn it off.

One thing to note, with 21 LEDs, they are numbered 0 to 20, not 1 to 21.

david_2018:
One thing to note, with 21 LEDs, they are numbered 0 to 20, not 1 to 21.

Oh yeah. Im so caught up with my for loop problem I forgot about them.. Thanks for reminding

So, do the LEDs light in the correct sequence and if so, when should they turn off ?

UKHeliBob:
So, do the LEDs light in the correct sequence and if so, when should they turn off ?

almost its 9 leds 1black and 10 leds lit, they will run indefinitely but they will be placed inside a function

void loop()
{
 byte offset = 2;
 for (int x = 10; x >= 0; x--)
 {
   leds[x]= CRGB::Red;
   leds [x+offset]= CRGB::Red;
   offset = offset + 2;
   FastLED.show();
   delay(100);

 }

I just just changed the offset to 1 although it doesn't have a gap in the middle but its good enough for me.. thank you for the help it saved me hours of frustrations :grinning: . I really appreciate it.

but its good enough for me.

You should be able to make it work fully by changing the for loop range and the offset but if it is good enough as it is then well done