head.write(90);
some servos may have errors, so they are not necessarily centered at 90 degrees, so be
fine-tuned where the servos are centered at 90 degrees. * /
delay(1000);
}
void
loop()
{
analogWrite(TrigPin, 0);
delayMicroseconds(2);
analogWrite(TrigPin, 255);
delayMicroseconds(10);
analogWrite(TrigPin, 0);
da
= pulseIn(EchoPin, HIGH) / 58.0;
if
(da
>=
50
&&
meaning that when the distance between the current obstacle and the car is greater than
or equal to 50, and less than or equal to 2000cm, execute the following program in {} *
/
{
int
val=150;
/ * When the straight line has a PWM value of 150, if the value is too
high, the speed of the car will be very fast, which may lead to the car can not hit the
obstacle in time when it encounters the obstacle. * /
analogWrite(E1, val);
digitalWrite(M2,0);
analogWrite(E2, val);
Serial.print("Distance =
Serial.print(da);
Serial.print("
Serial.println("Moving advance
delay(500);
/ * If the distance is more than 50cm, move forward and output "Moving
advance 50", indicating that the obstacle is more than 50cm from the car
}
if
(da
<40
&&
da
when the distance between the frontal obstacle and the car is greater than 30, and less
than 40cm, execute the following program in {} * /
{
int
val=130;
/ * The servos swivel to 90 (center) during initialization, because
// Low high and low send a short pulse to TrigPin)
da
<= 2000)
/ * Judge the collected value, da> = 50 && da <= 2000,
//the speed value of motorA is val
//the speed value of motorB is val
");
");
>30)
/ * Judge the collected value, da <50 && da> 30, meaning that
// Convert the echo time to cm
50");
75
digitalWrite(M1,0);
Need help?
Do you have a question about the Hummer-Bot and is the answer not in the manual?