/*************************************
 *          TIME:2022.1.24
 *     Development Team: Zhiyi Technology Co., Ltd.
 *     / Forward left and right backward function / 
 *          
 **************************************/

//Defines the L9110S motor drive pin

#define MOTOAR1 6    //6 port High level right wheel back
#define MOTOAR2 7  //7 port High level right wheel forward

#define MOTOBL1 9    //9 port High level left wheel back
#define MOTOBL2 8   //8 port High level left wheel forward

void forward()
{ 
 digitalWrite(MOTOAR1,LOW);
 digitalWrite(MOTOAR2,HIGH); //High level right wheel forward
  
 digitalWrite(MOTOBL1,LOW); 
 digitalWrite(MOTOBL2,HIGH);//High level left wheel forward

 Serial.println("Forward");//Sends a message to the serial monitor
}
/**************The trolley retreats**************/
void back()
{
  digitalWrite(MOTOAR1,HIGH); //High level right wheel back
  digitalWrite(MOTOAR2,LOW); 
  
  digitalWrite(MOTOBL1,HIGH); //High level left wheel back
  digitalWrite(MOTOBL2,LOW);
  Serial.println("Back");
}

void left()
{
  digitalWrite(MOTOAR1,LOW);  
  digitalWrite(MOTOAR2,HIGH); 
  
  digitalWrite(MOTOBL1,HIGH);  
  digitalWrite(MOTOBL2,LOW);

  Serial.println("Left");
}

void right(){
  digitalWrite(MOTOAR1,HIGH); 
  digitalWrite(MOTOAR2,LOW);  
  
  digitalWrite(MOTOBL1,LOW); 
  digitalWrite(MOTOBL2,HIGH); 

  Serial.println("Right");
}

void stop(){
  digitalWrite(MOTOAR1,LOW); 
  digitalWrite(MOTOAR2,LOW);  
  
  digitalWrite(MOTOBL1,LOW); 
  digitalWrite(MOTOBL2,LOW); 

  Serial.println("Stop");
}

//before execute loop() function, 
//setup() function will execute first and only execute once

void setup() 
{
  Serial.begin(9600); //open serial and set the baudrate
  pinMode(MOTOAR1,OUTPUT);//before useing io pin, pin mode must be set first 
  pinMode(MOTOAR2,OUTPUT);
  pinMode(MOTOBL1,OUTPUT);
  pinMode(MOTOBL2,OUTPUT);

}

//Repeat execution
void loop()
{
  forward();  //go forward 
  delay(2000);//delay 2000 ms
  back(); //go back    
  delay(2000);
  left();//turning left  
  delay(2000);
  right(); //turning right
  delay(2000);
  stop();
  delay(2000);
}
