Seamless LED Animation

Attempting to code an LED animation that looks like a comet running down the length of the led strip of 422 leds. The beginning and the end of the strip are budded against each other, and ive been trying different approaches to get the effect to immediately start once the end is hit to avoid any visual breaks. Right now i have the code running an extra 40 pixels to entirely hide the animation once it hits the end or else the pixel will remain on. The entire effect is 40 pixels in length ie it has to run those extra pixels to create a turned off strip.

Im trying to avoid a for loop in a for loop to draw the 40 pixel effect, so ive setting the color of each pixel and then show it. The problem is when the counter hits zero, its telling negative number of pixels location (ie number -40 pixel location) a color value when instead it should be telling pixel (422-40 = 382 pixel) that command. Any help would be appreciated, thanks.

#include <Adafruit_NeoPixel.h>
#define PIN 11
#define NUM_LEDS 422
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_WRGB + NEO_KHZ800);
int OFFSET;

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all piiels to 'off'
}

void loop() {
  for (int i = 0; i < NUM_LEDS + 40; i++) {
    strip.setPixelColor(i, strip.Color(255, 255, 0, 255));
    OFFSET = 1;
    strip.setPixelColor(i - OFFSET, strip.Color(243, 243, 0, 243));
    OFFSET = 2;
    strip.setPixelColor(i - OFFSET, strip.Color(236, 236, 0, 236));
    OFFSET = 3;
    strip.setPixelColor(i - OFFSET, strip.Color(230, 230, 0, 230));
    OFFSET = 4;
    strip.setPixelColor(i - OFFSET, strip.Color(224, 224, 0, 224));
    OFFSET = 5;
    strip.setPixelColor(i - OFFSET, strip.Color(218, 218, 0, 218));
    OFFSET = 6;
    strip.setPixelColor(i - OFFSET, strip.Color(212, 212, 0, 212));
    OFFSET = 7;
    strip.setPixelColor(i - OFFSET, strip.Color(205, 205, 0, 205));
    OFFSET = 8;
    strip.setPixelColor(i - OFFSET, strip.Color(199, 199, 0, 199));
    OFFSET = 9;
    strip.setPixelColor(i - OFFSET, strip.Color(193, 193, 0, 193));
    OFFSET = 10;
    strip.setPixelColor(i - OFFSET, strip.Color(187, 187, 0, 187));
    OFFSET = 11;
    strip.setPixelColor(i - OFFSET, strip.Color(181, 181, 0, 181));
    OFFSET = 12;
    strip.setPixelColor(i - OFFSET, strip.Color(174, 174, 0, 174));
    OFFSET = 13;
    strip.setPixelColor(i - OFFSET, strip.Color(168, 168, 0, 168));
    OFFSET = 14;
    strip.setPixelColor(i - OFFSET, strip.Color(162, 162, 0, 162));
    OFFSET = 15;
    strip.setPixelColor(i - OFFSET, strip.Color(156, 156, 0, 156));
    OFFSET = 16;
    strip.setPixelColor(i - OFFSET, strip.Color(150, 150, 0, 150));
    OFFSET = 17;
    strip.setPixelColor(i - OFFSET, strip.Color(143, 143, 0, 143));
    OFFSET = 18;
    strip.setPixelColor(i - OFFSET, strip.Color(137, 137, 0, 137));
    OFFSET = 19;
    strip.setPixelColor(i - OFFSET, strip.Color(131, 131, 0, 131));
    OFFSET = 20;
    strip.setPixelColor(i - OFFSET, strip.Color(125, 125, 0, 125));
    OFFSET = 21;
    strip.setPixelColor(i - OFFSET, strip.Color(119, 119, 0, 119));
    OFFSET = 22;
    strip.setPixelColor(i - OFFSET, strip.Color(112, 112, 0, 112));
    OFFSET = 23;
    strip.setPixelColor(i - OFFSET, strip.Color(106, 106, 0, 106));
    OFFSET = 24;
    strip.setPixelColor(i - OFFSET, strip.Color(100, 100, 0, 100));
    OFFSET = 25;
    strip.setPixelColor(i - OFFSET, strip.Color(90, 90, 0, 90));
    OFFSET = 26;
    strip.setPixelColor(i - OFFSET, strip.Color(70, 70, 0, 70));
    OFFSET = 27;
    strip.setPixelColor(i - OFFSET, strip.Color(55, 55, 0, 55));
    OFFSET = 28;
    strip.setPixelColor(i - OFFSET, strip.Color(43, 43, 0, 43));
    OFFSET = 29;
    strip.setPixelColor(i - OFFSET, strip.Color(34, 34, 0, 34));
    OFFSET = 30;
    strip.setPixelColor(i - OFFSET, strip.Color(28, 28, 0, 28));
    OFFSET = 31;
    strip.setPixelColor(i - OFFSET, strip.Color(22, 22, 0, 22));
    OFFSET = 32;
    strip.setPixelColor(i - OFFSET, strip.Color(18, 18, 0, 18));
    OFFSET = 33;
    strip.setPixelColor(i - OFFSET, strip.Color(15, 15, 0, 15));
    OFFSET = 34;
    strip.setPixelColor(i - OFFSET, strip.Color(12, 12, 0, 12));
    OFFSET = 35;
    strip.setPixelColor(i - OFFSET, strip.Color(10, 10, 0, 10));
    OFFSET = 36;
    strip.setPixelColor(i - OFFSET, strip.Color(8, 8, 0, 8));
    OFFSET = 37;
    strip.setPixelColor(i - OFFSET, strip.Color(7, 7, 0, 7));
    OFFSET = 38;
    strip.setPixelColor(i - OFFSET, strip.Color(6, 6, 0, 6));
    OFFSET = 39;
    strip.setPixelColor(i - OFFSET, strip.Color(5, 5, 0, 5));
    OFFSET = 40;
    strip.setPixelColor(i - OFFSET, strip.Color(0, 0, 0, 0));
    strip.show();
  }
}

OK, so reassure us you are not using an ATmega328-based processor as there are too many LEDs (422) for its memory.

Next, that code is just mind-bending. :roll_eyes:

I see that each of the strip.Color steps uses only one colour parameter. Please make an constant array of those parameters and put them in a loop using the loop index instead of "OFFSET".

Then we may have half a chance of solving the negative problem using the remainder (%) function.

Yes ,Im not using a ATmega328 but rather a Mega. The uno would not cut it for all these leds. Actually just stumbled upon the solution by adding the snippet of code below. It just turns off the led 382 pixels ahead of the first pixel. Everything is working as intended.

strip.setPixelColor(i +382, strip.Color(0, 0, 0, 0));