Programme robot
TD : Programme robot. Recherche parmi 300 000+ dissertationsPar Mattsupdu92 • 9 Avril 2022 • TD • 545 Mots (3 Pages) • 298 Vues
#define ML_Ctrl 5 //define direction control pin of B motor
#define ML_PWM 5 //define PWM control pin of B motor
#define MR_Ctrl 6 //define direction control pin of A motor
#define MR_PWM 6 //define PWM control pin of A motor
const int sensor_l = 11;//define the pin of left line tracking sensor
const int sensor_c = 7;//define the pin of middle line tracking sensor
const int sensor_r = 8;//define the pin of right line tracking sensor
int l_val,c_val,r_val;//define these variables
void setup() {
Serial.begin(9600);//start serial monitor and set baud rate to 9600
pinMode(ML_Ctrl, OUTPUT);//set direction control pin of B motor
pinMode(ML_PWM, OUTPUT);//set PWM control pin of B motor to OUTPUT
pinMode(MR_Ctrl, OUTPUT);//set direction control pin of A motor to OUTPUT
pinMode(MR_PWM, OUTPUT);//set PWM control pin of A motor to OUTPUT
pinMode(sensor_l,INPUT);//set the pins of left line tracking sensor to INPUT
pinMode(sensor_c,INPUT);//set the pins of middle line tracking sensor to INPUT
pinMode(sensor_r,INPUT);//set the pins of right line tracking sensor to INPUT
}
void loop()
{
tracking(); //run main program
}
void tracking()
{
l_val = digitalRead(sensor_l);//read the value of left line tracking sensor
c_val = digitalRead(sensor_c);//read the value of middle line tracking sensor
r_val = digitalRead(sensor_r);//read the value of right line tracking sensor
if(c_val == 1)//if the state of middle one is 1, which means detecting black line
{
front();//car goes forward
}
else
{
if((l_val == 1)&&(r_val == 0))//if only left line tracking sensor detects black trace
{
left();//car turns left
}
else if((l_val == 0)&&(r_val == 1))//if only right line tracking sensor detects black trace
{
right();//car turns right
}
else// if left and right line tracking sensors detect black trace or they don’t read
...