#include <Servo.h>

const int pinUR = A3;  // Upper Right
const int pinUL = A1;  // Upper Left
const int pinLL = A0;  // Lower Left
const int pinLR = A5;  // Lower Right

int UL = 0;
int UR = 0;
int LL = 0;
int LR = 0;

Servo myServo;  // Create a servo object
Servo myServo1;

void setup() {
    Serial.begin(9600);       // Initialize serial communication
    myServo.attach(9);        // Attach the first servo to pin 9
    myServo1.attach(10);      // Attach the second servo to pin 10
    myServo1.write(120);      // Initialize the second servo at 120°
}

void loop() {
    // Read light intensity values
    UR = analogRead(pinUR);
    UL = analogRead(pinUL);
    LL = analogRead(pinLL);
    LR = analogRead(pinLR);

    // Print sensor values for debugging
    Serial.print("Sensor UR: "); Serial.print(UR);
    Serial.print(" | Sensor UL: "); Serial.print(UL);
    Serial.print(" | Sensor LL: "); Serial.print(LL);
    Serial.print(" | Sensor LR: "); Serial.println(LR);

    // Determine which sensor detects the most light
    if (UL < UR && UL < LL && UL < LR) {
        myServo.write(180);  
        myServo1.write(90);
// Move servo to 90° for UL
        Serial.println("Servo moved to 90° (UL has the most light)");
    } else if (UR < UL && UR < LL && UR < LR) {
        myServo.write(90);  // Move servo to 0° for UR
        myServo1.write(90);
        Serial.println("Servo moved to 0° (UR has the most light)");
    } else if (LL < UL && LL < UR && LL < LR) {
        myServo.write(90); 
        myServo1.write(180);
 // Move servo to 180° for LL
        Serial.println("Servo moved to 180° (LL has the most light)");
    } else if (LR < UL && LR < UR && LR < LL) {
        myServo.write(0); 
        myServo1.write(90);
 // Move servo to 135° for LR (simulating 270°)
        Serial.println("Servo moved to 135° (LR has the most light)");
    } else {
        Serial.println("No clear light direction detected.");
    }

    delay(550);  // Delay for stability
}
