#include <Adafruit_NeoPixel.h>

// Define pin and number of LEDs
#define PIN 4
#define NUM_LEDS 24

// Create the NeoPixel object
Adafruit_NeoPixel ring = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

// Function to display a rainbow animation
void rainbowAnimation1() {
  for (int i = 0; i < 256; i++) {
    for (int j = 0; j < NUM_LEDS; j++) {
      ring.setPixelColor(j, ring.ColorHSV((i + j * 256 / NUM_LEDS) % 65536, 255, 255));
    }
    ring.show();
    delay(50);
  }
}

void rainbowAnimation2() {
  for (int i = 0; i < NUM_LEDS; i++) {
    ring.clear();
    ring.setPixelColor(i, ring.ColorHSV(i * 65536 / NUM_LEDS, 255, 255));
    ring.show();
    delay(100);
  }
}

void rainbowAnimation3() {
  for (int i = 0; i < 256; i += 5) {
    for (int j = 0; j < NUM_LEDS; j++) {
      uint16_t hue = (j * 256 / NUM_LEDS + i) % 256;
      ring.setPixelColor(j, ring.ColorHSV(hue * 256, 255, 255));
    }
    ring.show();
    delay(30);
  }
}

void rainbowAnimation4() {
  for (int i = 0; i < NUM_LEDS; i++) {
    for (int j = 0; j < NUM_LEDS; j++) {
      int colorOffset = (j + i) % NUM_LEDS;
      ring.setPixelColor(j, ring.ColorHSV(colorOffset * 65536 / NUM_LEDS, 255, 255));
    }
    ring.show();
    delay(100);
  }
}

void rainbowAnimation5() {
  for (int i = 0; i < 256; i++) {
    ring.clear();
    for (int j = 0; j < NUM_LEDS; j += 3) {
      int hue = (i + j * 8) % 256;
      ring.setPixelColor(j, ring.ColorHSV(hue * 256, 255, 255));
    }
    ring.show();
    delay(50);
  }
}

void rainbowAnimation6() {
  for (int i = 0; i < NUM_LEDS; i++) {
    ring.clear();
    for (int j = 0; j < NUM_LEDS; j++) {
      if ((i + j) % 2 == 0) {
        ring.setPixelColor(j, ring.ColorHSV(j * 65536 / NUM_LEDS, 255, 255));
      }
    }
    ring.show();
    delay(100);
  }
}

void rainbowAnimation7() {
  for (int i = 0; i < 256; i++) {
    for (int j = 0; j < NUM_LEDS; j++) {
      ring.setPixelColor(j, ring.ColorHSV((i + j * 256 / NUM_LEDS) % 65536, 255, (i * 255 / 256)));
    }
    ring.show();
    delay(50);
  }
}

void setup() {
  ring.begin();
  ring.show();
}

void loop() {
  // Play each rainbow animation one by one
  rainbowAnimation1();
  delay(1000);
  rainbowAnimation2();
  delay(1000);
  rainbowAnimation3();
  delay(1000);
  rainbowAnimation4();
  delay(1000);
  rainbowAnimation5();
  delay(1000);
  rainbowAnimation6();
  delay(1000);
  rainbowAnimation7();
  delay(1000);
}