#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_NeoPixel.h>

#define PIN1 6 // Pin for the first ARGB strip
#define PIN2 7 // Pin for the second ARGB strip
#define NUMPIXELS 4 // Number of LEDs in each ARGB strip

Adafruit_MPU6050 mpu;
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);
  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'
  
  strip2.begin();
  strip2.show(); // Initialize all pixels to 'off'

  // Initialize MPU6050
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_5_HZ);
}

void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  // Clear all LEDs on both strips
  strip1.clear();
  strip2.clear();

  if (a.acceleration.x < -2) {
    // Tilted left
    for (int i = 0; i < 4; i++) {
      strip1.setPixelColor(i, strip1.Color(255, 0, 0)); // Red color on the first strip
      strip2.setPixelColor(i, strip2.Color(255, 0, 0)); // Red color on the second strip
    }
  } else if (a.acceleration.x > 2) {
    // Tilted right
    for (int i = 4; i < 8; i++) {
      strip1.setPixelColor(i, strip1.Color(0, 0, 255)); // Blue color on the first strip
      strip2.setPixelColor(i, strip2.Color(0, 0, 255)); // Blue color on the second strip
    }
  }

  strip1.show(); // Update the first strip
  strip2.show(); // Update the second strip
  delay(100);
}
