#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C Icd(0x27, 16, 2);
#define Trig 4
#define Echo 3
#define R 10
#define G 11
#define B 12
long width, distance;
void setup()
{
  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);
  Icd.init();
  Icd.backlight();
  Icd.setCursor(1, 0);
  Icd.print("malak");
  Icd.setCursor(3, 1);
  Icd.print("espanioly");
  delay(2000);
  Icd.clear();
}
void loop()
{
  if(US_READER() < 50)
  RGB(1,0,0);
  else if(US_READER() <100)
  RGB(0,0,1);
}
void RGB (int r , int g, int b )
{
  digitalWrite(R, r);
  digitalWrite(G, g);
  digitalWrite(B, b);
}
int US_READER()
{
  digitalWrite(Trig, 0);
  delayMicroseconds(2);
  digitalWrite(Trig, 1);
  delayMicroseconds(10);
  digitalWrite(Trig, 0);
  width = pulseIn(Echo, 1);
  distance = width /58.2;
  Icd.print("Distance is : ");
  Icd.setCursor(5, 1);
  Icd.print(distance);
  Icd.println("cm");
  return distance;
}