#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  // Address can be 0x27
#define LM1 2
#define LM2 3
#define RM1 4
#define RM2 5
#define FL 6
#define RL 7
#define BL 8
#define LL 9
#define BUZZER 13
int i;

void setup()
{
  for (i=2; i<=9; i++)
  pinMode(i,OUTPUT);
  pinMode(BUZZER, OUTPUT);
  lcd.init();                       
  lcd.backlight();
  lcd.setCursor(2,0);
  lcd.print("Danya Zreqqy");
  lcd.setCursor(4,1);
  lcd.print("Robot IR");
  delay(3000);
  lcd.clear();
}

void loop()
{
  RobotGo();
  delay(3000);
  Stop();
  delay(500);

  RobotBack();
  delay(3000);
  Stop();
  delay(500);

  Left();
  delay(3000);
  Stop();
  delay(500);

  Right();
  delay(3000);
  Stop();
  delay(500);

  for (i=2; i<=5; i++)
  {
  digitalWrite(i,0);
  digitalWrite(BL,1);
  delay(1500);
  }

}

void RobotGo()
{
  digitalWrite(LM1, 1);
  digitalWrite(LM2, 0);
  digitalWrite(RM1, 1);
  digitalWrite(RM2, 0);
  digitalWrite(FL, 1);
  digitalWrite(RL, 0);
  digitalWrite(LL, 0);
  digitalWrite(BL, 0);
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Robot IR");
  lcd.setCursor(7,1);
  lcd.print("Go");

}

void Stop()
{
  for (i=2; i<=9; i++)
  digitalWrite(i, 0);
}
void RobotBack()
{
  digitalWrite(LM1,0);
  digitalWrite(LM2,1);
  digitalWrite(RM1,0);
  digitalWrite(RM2,1);
  digitalWrite(FL,0);
  digitalWrite(RL,0);
  digitalWrite(LL,0);
  digitalWrite(BL,1);
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Robot IR");
  lcd.setCursor(4,1);
  lcd.print("go back");


  for(i=2; i<=9; i++)
  {
    digitalWrite(BUZZER,1);
    delay(100);
    digitalWrite(BUZZER,0);
    delay(100);
  }
}

void Left()
{
  digitalWrite(LM1,1);
  digitalWrite(LM2,0);
  digitalWrite(RM1,0);
  digitalWrite(RM2,0);
  digitalWrite(FL,0);
  digitalWrite(RL,1);
  digitalWrite(LL,0);
  digitalWrite(BL,0);
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Robot IR");
  lcd.setCursor(4,1);
  lcd.print("go left");


}
void Right()
{
  digitalWrite(LM1,0);
  digitalWrite(LM2,0);
  digitalWrite(RM1,1);
  digitalWrite(RM2,0);
  digitalWrite(FL,0);
  digitalWrite(RL,0);
  digitalWrite(LL,1);
  digitalWrite(BL,0);
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Robot IR");
  lcd.setCursor(4,1);
  lcd.print("go right");


}