#include "Ultrasonic.h"

Ultrasonic ultrasonic(12, 13);
int distance;
int LED1 = 3;
int LED2 = 4;
int LED3 = 5;

void setup() {
  // put your setup code here, to run once:
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  distance = ultrasonic.read(CM);
  Serial.print("Distance en CM: ");
  Serial.println(distance);
  delay(1000);

  // Éteindre toutes les LEDs au début
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);

  if (distance < 100) {
    digitalWrite(LED1, HIGH);
  } else if (distance >= 100 && distance <= 300) {
    digitalWrite(LED2, HIGH);
  } else {
    digitalWrite(LED3, HIGH);
  }
}