#include<Tone.h>
const int trigpin = A1;
const int echopin = A3;
const int Button = A4;
const int ledrouge=A0;
const int ledorangé=A2;
const int ledvert=A5;
const int buzzer=A6;
int buttonstate;
int Rep;
void setup() {
  Serial.begin(9600);
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  pinMode(Button, INPUT_PULLUP);
  pinMode(ledrouge, OUTPUT);
  pinMode(ledorangé, OUTPUT);
  pinMode(ledvert, OUTPUT);
  pinMode(buzzer, OUTPUT);
}


void loop() {
  buttonstate=digitalRead(Button);
  if (buttonstate == HIGH ) {
    digitalWrite(trigpin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigpin, LOW);
    int duration = pulseIn(echopin, HIGH);
    float distance = duration / 58.0;
    Serial.print("Distance in CM: ");
    Serial.println(distance);
    if(distance<30)
    {
      digitalWrite(ledrouge, HIGH);
      digitalWrite(ledorangé, LOW);
      digitalWrite(ledvert, LOW);
      tone(buzzer, 440, 0);
      }
    else if(distance>30 && distance<=120)
    {
      digitalWrite(ledrouge, LOW);
      digitalWrite(ledorangé, HIGH);
      digitalWrite(ledvert, LOW);
      int Rep=map(distance,0,90,10,1000);
      tone(buzzer, 440,Rep);
      }
    else if(distance>120){
      digitalWrite(ledrouge, LOW);
      digitalWrite(ledorangé, LOW);
      digitalWrite(ledvert, HIGH);
      noTone(buzzer);
}
}

    delay(1000);
    
  }

$abcdeabcde151015202530354045505560fghijfghij