#include <Adafruit_NeoPixel.h>

#define PIR_SENSOR_PIN 4  // GPIO 04
#define BUZZER_PIN 5     // GPIO 5, correct GPIO pin based on your setup
#define RGB_LED_PIN 25    // GPIO 25

Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, RGB_LED_PIN);

void setup() {
  Serial.begin(115200);
  pinMode(PIR_SENSOR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  strip.begin();
  strip.show();
}

void setRGBColor(int index, uint8_t red, uint8_t green, uint8_t blue) {
  strip.setPixelColor(index, strip.Color(red, green, blue));
}

void loop() {
  int motionValue = digitalRead(PIR_SENSOR_PIN);

  if (motionValue == HIGH) {
    Serial.println("Motion detected!");

    // Buzzer Test with tone()
    tone(BUZZER_PIN, 1000, 1000); // 1000 Hz frequency, 2000 ms duration
    delay(1000); // Wait for the tone to complete
    noTone(BUZZER_PIN); // Stop the tone

    // RGB LEDs Test
    for (int i = 0; i < 5; i++) {
      setRGBColor(i, 255, 255, 255);
    }
    strip.show();
    delay(2000);

    for (int i = 0; i < 5; i++) {
      setRGBColor(i, 0, 0, 0);
    }
    strip.show();
  }

  delay(1000);  // Adjust the delay according to your needs
}