const int PIN_TRIG=A1;
const int PIN_ECHO=A0;
const int buttonPin=A2;
const int buzzer=A6;
const int led_red=A5;
const int led_yellow=A4;
const int led_green=A3;

int mp;


void setup(){
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(PIN_TRIG, OUTPUT);
  pinMode(PIN_ECHO, INPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(led_red, OUTPUT);
  pinMode(led_yellow, OUTPUT);
  pinMode(led_green, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  if (digitalRead(buttonPin)==HIGH){
  digitalWrite(PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_TRIG, LOW);
  int duree= pulseIn(PIN_ECHO,HIGH);
  float distance = duree/58.0;
  Serial.print("la distance en cm: ");
  Serial.println(duree/58);
  if (distance<30){
    digitalWrite(buzzer, HIGH);
    digitalWrite(led_green, LOW);
    digitalWrite(led_red, HIGH);
    digitalWrite(led_yellow, LOW);
    digitalWrite(buzzer, LOW);
    tone(buzzer,400);}
  else if(distance>=30 && distance<=120){
    digitalWrite(led_green, LOW);
    digitalWrite(led_red, LOW);
    digitalWrite(led_yellow, HIGH);
    mp=map(distance,-30,90,10,1000);
    tone(buzzer,440,mp);}
  else if (distance>=120){
    digitalWrite(led_green, HIGH);
    digitalWrite(led_red, LOW);
    digitalWrite(led_yellow, LOW);
    
    noTone(buzzer);
  }
  
  delay(1000); // this speeds up the simulation
  }
}
$abcdeabcde151015202530fghijfghij