Keyestudio Ks0428 Manual page 235

Table of Contents

Advertisement

www.keyestudio.com
for (int j = 1; j <= 10; j = j + (1)) { ///for statement, the data
will be more accurate if ultrasonic sensor detect a few times.
a1 = checkdistance(); //assign the left distance detected
by ultrasonic sensor to variable a1
}
delay(200);
procedure(20); //Ultrasonic platform turns right
for (int k = 1; k <= 10; k = k + (1)) {
a2 = checkdistance(); //assign the right distance detected
by ultrasonic sensor to variable a2
}
if (a1 < 50 || a2 < 50) //robot will turn to the longer distance
side when left or right distance is less than 50cm.if the left or right
distance is less than 50cm, the robot will turn to the greater
distance
{
if (a1 > a2) //left distance is greater than right
{
procedure(90); //Ultrasonic platform turns back to right
ahead ultrasonic platform turns front
Car_left(); //robot turns left
delay(500); //turn left 500ms
Car_front(); //go forward
235

Advertisement

Table of Contents
loading

Table of Contents