#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int red = 9;
int blue = 10;
int green = 11;
int echo = 4;
int trig = 5;
int time;
int distance;

void setup() {
  // put your setup code here, to run once:
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);

}
void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  time = pulseIn(echo, HIGH);
  distance = (0.034*time)/2;
  Serial.print("Distance = ");
  Serial.println(distance);
  if (distance<100){
    digitalWrite(red, 0);
    digitalWrite(green, 255);
    digitalWrite(blue, 255);
    lcd.setCursor(0,0);
    lcd.print("DANGER");
    delay(1000);
  }
  else if (distance>300){
    digitalWrite(red, 255);
    digitalWrite(green, 0);
    digitalWrite(blue, 255);
    lcd.setCursor(0,0);
    lcd.print("SAFETY ALERT");
    delay(1000);
  }
  else if ((distance>=100) and (distance<=300)){
    digitalWrite(red, 0);
    digitalWrite(green, 0);
    digitalWrite(blue, 255);
    lcd.setCursor(0,0);
    lcd.print("WARNING ALRET");
    delay(1000);
  }
}
//void led_color(int red_value, int green_value, int blue_value)

  // put your main code here, to run repeatedly:
  //analogWrite(red, red_value);
  //analogWrite(blue, blue_value);
  //analogWrite(green, green_value);