#include <Adafruit_NeoPixel.h>

#define PIN            6   // Connect the NeoPixel data pin to Arduino pin 6
#define NUM_LEDS       24  // Number of LEDs in the ring

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

void setup() {
  Serial.begin(115200);   // Init Serial at 115200 Baud
  Serial.println("Serial Working"); // Test to check if serial is working or not
  strip.begin();           // Initialize NeoPixel strip
}

void loop() {
  int sensorStatus1 = digitalRead(9); // Assuming IRSensor1 is connected to pin 9

  if (sensorStatus1 == 1) {
    // No motion detected
    strip.fill(strip.Color(0, 0, 0)); // Fill with black (turn off)
    strip.show();
    delay(5000);
  } else {
    // Motion detected
    rainbowEffect();
    Serial.println("Motion Detected!"); // Print "Motion Detected!" on the serial monitor window
  }
}

void rainbowEffect() {
  for (int i = 0; i < NUM_LEDS; i++) {
    strip.setPixelColor(i, Wheel((i * 256 / NUM_LEDS) & 255));
  }
  strip.show();
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
