LED strip cant handle negative LED numbers??

I am using a strand of WS2812B RGB LEDs 144/m. I am using the FastLED library for my programming. I have done several projects with these lights and know that my wiring and power supply are adequate. My problem is that I am trying to have several sets of colors chase down the LED strip with a break in between and my code produces a negative LED number until it iterates high enough to be a positive number, this causes my LED strip to lock up and not do anything after loading. if i comment out the lines that produce a negative LED number at the start it works just find with a single set that chase. I have watched other youtube videos that use the FastLED library to produce this effect with success. Can anyone tell me what is wrong and if you are just no longer able to do this effect this way?

#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 144
CRGB leds[NUM_LEDS];

void setup() {
int BRIGHTNESS=50;
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
}

void loop() {
// put your main code here, to run repeatedly:

for (int i=0; i<164; i++){
leds[i-20] = CRGB (0, 0, 0);
leds[i-9] = CRGB (255, 255, 0);
leds[i-7] = CRGB (0, 0, 0);
leds = CRGB (255, 0, 0);

  • FastLED.show();*
  • delay(1);*
    }
    }

Rewrite your code that there are no negative numbers - isn't that obvious?
You could start with: for (int i = 20 ...

this causes my LED strip to lock up and not do anything after loading

This is nothing to do with the LEDs it is to do with your code. You can’t send a negitave number of packets of data that is all the LEDs cair about.

Your code however does cair, you are accessing numbers from a place where they have not been allocated, these places can hold vital values that control the running of the code, so you must never have a negative array index.

You are writing outside of the array. Don't do that.

Maybe a helper function comes in handy... something similar to this:

void setLed(int pos, CRGB colour){
  if(pos < 0) return;
  if(pos >= NUM_LEDS) return;
  leds[pos] = colour;
}

Or use the modulo function (%), like this :

for (int i=0; i<164; i++){
   leds[(i-20)%NUM_LEDS] = CRGB (0, 0, 0);
   leds[(i-9)%NUM_LEDS] = CRGB (255, 255, 0);
   leds[(i-7)%NUM_LEDS] = CRGB (0, 0, 0);
   leds = CRGB (255, 0, 0); // <--- This line is not correct
   FastLED.show();
   delay(1);
}

This ensures that the array index always remains between 0 and NUM_LEDS.

Also :
  leds = CRGB (255, 0, 0); // <--- This line is not correctleds is an array and CRGB(255,0,0) is a number.