#define LED_VERT 4
#define LED_JAUNE 3
#define LED_ROUGE 2
#define PIN_TRIG 1
#define PIN_ECHO 0
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

void setup() {
  lcd.begin(16, 2);
  pinMode(LED_VERT, OUTPUT);
  pinMode(LED_JAUNE, OUTPUT);
  pinMode(LED_ROUGE, OUTPUT);
  pinMode(PIN_TRIG, OUTPUT);
  pinMode(PIN_ECHO, INPUT);
}

void loop() {
  int LED_state[] = {LED_VERT, LED_JAUNE, LED_ROUGE};
  digitalWrite(PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_TRIG, LOW);
  digitalWrite(LED_VERT, LOW);
  digitalWrite(LED_JAUNE, LOW);
  digitalWrite(LED_ROUGE, LOW);
  int duree=pulseIn(PIN_ECHO, HIGH);
  duree/=58;
  lcd.clear();
  if (duree<=150){
    //lcd.print("background": "green", "color": "black");
    lcd.print("Je vire a droite");
    digitalWrite(LED_state[0], HIGH);
  }
  else if(duree<=300){
    //lcd.print("background": "yellow", "color": "black");
    lcd.print(" Je garde ma ");
    lcd.setCursor(2, 1);
    lcd.print("position");
    digitalWrite(LED_state[1], HIGH);
  }
  else
  {
    //lcd.print("background": "red", "color": "black");
    lcd.print("Je vire a gauche");
    digitalWrite(LED_state[2], HIGH);
  }
  delay(1000);

  /*for (int i = 0; i < 3; i++) {
    digitalWrite(LED_VERT, LOW);
    digitalWrite(LED_JAUNE, LOW);
    digitalWrite(LED_ROUGE, LOW);
    digitalWrite(LED_state[i], HIGH);
    lcd.print(message[i]);
    delay(5000);
    lcd.clear();
  }
  */

}