const int LDR_PIN = A0;
const int TRIG_PIN = 9;
const int ECHO_PIN = 10;
const int LED_PIN = 13;

void setup() {
  Serial.begin(9600);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
}

int LDR() {
  
  int ldrValue = analogRead(LDR_PIN);
  if (ldrValue < 500) {
    Serial.println("LIGHT LOW");
    digitalWrite(LED_PIN, HIGH); // Turn on LED for indication
    return 1;
  } else {
    digitalWrite(LED_PIN, LOW); // Turn off LED
    return 0;
  }
}

int Ultrasonic() {
  
  long duration, distance;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;
  if (distance < 20) {
    Serial.println("DISTANCE NEAR");
    digitalWrite(LED_PIN, HIGH); // Turn on LED for indication
    return 1;
  } else {
    digitalWrite(LED_PIN, LOW); // Turn off LED
    return 0;
  }
}

void loop() {
  int dataArray[] = {1, 2, 3};
  
  for (int i = 0; i < 3; i++) {
    int sensorType = dataArray[i];
  
    if (sensorType == 1) {
      if (LDR() == 1) {
      
      } else {
      
      }
    } 
    else if (sensorType == 2) {
      if (Ultrasonic() == 1) {
        
      } else {
        
      }
    } 
    else if (sensorType == 3) {
      
      Serial.println("DONE");
      digitalWrite(LED_PIN, LOW); 
    }
    delay(1000); // Delay for stability
  }
}