20
pinMode(SensorLeft, INPUT); // Set left Line Walking Infrared sensor as input
pinMode(SensorRight_2, INPUT); //Set Right Infrared sensor as input
pinMode(SensorLeft_2, INPUT); //Set left Infrared sensor as input
digitalWrite(key,HIGH);//Initialize button
digitalWrite(beep,HIGH);// set buzzer mute
}
//=======================Motor=========================
void run()
{
digitalWrite(Right_motor_go,HIGH);// right motor go ahead
digitalWrite(Right_motor_back,LOW);
analogWrite(Right_motor_go,100);//PWM--Pulse Width Modulation(0~255). It can be
adjusted to control speed.
analogWrite(Right_motor_back,0);
digitalWrite(Left_motor_go,HIGH);// set left motor go ahead
digitalWrite(Left_motor_back,LOW);
analogWrite(Left_motor_go,100);//PWM--Pulse Width Modulation(0~255). It can be
adjusted to control speed.
analogWrite(Left_motor_back,0);
}
void brake() //stop
{
digitalWrite(Right_motor_go,LOW);
digitalWrite(Right_motor_back,LOW);
digitalWrite(Left_motor_go,LOW);
digitalWrite(Left_motor_back,LOW);
}
void left()//turn left
{
digitalWrite(Right_motor_go,HIGH); // right motor go ahead
digitalWrite(Right_motor_back,LOW);
analogWrite(Right_motor_go,100);
analogWrite(Right_motor_back,0);// PWM--Pulse Width Modulation(0~255) control
speed
digitalWrite(Left_motor_go,LOW); // left motor stop
digitalWrite(Left_motor_back,LOW);
analogWrite(Left_motor_go,0);
analogWrite(Left_motor_back,0);// PWM--Pulse Width Modulation(0~255) control
speed
}
void spin_left(int time) //Left rotation
{
digitalWrite(Right_motor_go,HIGH); // right motor go ahead
digitalWrite(Right_motor_back,LOW);
analogWrite(Right_motor_go,100); // PWM--Pulse Width Modulation(0~255) control
speed
analogWrite(Right_motor_back,0);
digitalWrite(Left_motor_go,LOW); // left motor back off
digitalWrite(Left_motor_back,HIGH);
analogWrite(Left_motor_go,0);
analogWrite(Left_motor_back,100); // PWM--Pulse Width Modulation(0~255) control
speed