#include <Adafruit_NeoPixel.h>

#define PIN            7   // Pin connected to the NeoPixels
#define NUM_PIXELS     40  // Total number of NeoPixels

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);

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

void loop() {
  // Define the number of pixels in each segment
  int segmentSizes[] = {8, 13, 5, 7, 7};

  // Define the colors for each segment
  uint32_t segmentColors[] = {strip.Color(0, 0, 255), strip.Color(0, 0, 255),
                              strip.Color(0, 0, 255), strip.Color(0, 0, 255),
                              strip.Color(0, 0, 255)};

  // Turn off all LEDs
  for (int i = 0; i < NUM_PIXELS; i++) {
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  }
  
  int startIndex = 0;
  
  // Loop through the segments
  for (int segmentIndex = 0; segmentIndex < 5; segmentIndex++) {
    int segmentSize = segmentSizes[segmentIndex];
    uint32_t segmentColor = segmentColors[segmentIndex];
    
    // Turn on the current segment in the specified color
    for (int i = startIndex; i < startIndex + segmentSize; i++) {
      strip.setPixelColor(i, segmentColor);
    }
    
    strip.show();
    delay(200);  // Adjust the delay for the chasing speed
    
    // Turn off the current segment
    for (int i = startIndex; i < startIndex + segmentSize; i++) {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
    }
    
    // Move to the next segment
    startIndex += segmentSize;
  }
}