right
= analogRead(rightPin);
analogWrite(TrigPin, 0);
delayMicroseconds(2);
analogWrite(TrigPin, 255);
delayMicroseconds(10);
analogWrite(TrigPin, 0);
da
= pulseIn(EchoPin, HIGH) / 58.0;
if
(da
>=
50
&&
da
= 50 && da <= 2000, 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. */
digitalWrite(M1, 0);
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
>
&& da > 30, meaning that 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;
digitalWrite(M1, 0);
analogWrite(E1, val);
digitalWrite(M2, 0);
analogWrite(E2, val);
Serial.print("Distance =
Serial.print(da);
Serial.print("
Serial.println("Moving
//delay(500);/* If the distance is more than 40cm, move forward and output "Moving advance 40",
indicating that the obstacle is more than 40cm from the car*/
}
if
((left
<= 38) &&
digitalWrite(M1, HIGH);
analogWrite(E1, 0);
analogWrite(M2, 0);
analogWrite(E2, 250);
// Low high and low send a short pulse to TrigPin)
// Convert the echo time to cm
<=
2000
&&
(left
>= 38) &&
//the speed value of motorA is val
//the speed value of motorB is val
");
");
50");
30
&&
(left
>= 38) &&
//the speed value of motorA is val
//the speed value of motorB is val
");
");
advance40");
(right
>= 38) &&
(da
//the speed value of motorA is val
//the speed value of motorA is val
(right
>= 38))
(right
>= 38))
{/* Judge the collected value, da < 50
>=
30
&&
da
<= 1000)) {
73
{/* Judge the collected value, da>
Need help?
Do you have a question about the Hummer-Bot-1.0 and is the answer not in the manual?
Questions and answers