61
customize the other values, if the use of digital port to receive the value of the sensor returns
only "0" and "1", but to determine the same way. The reason why I did not use digital IO, because
we use the digital IO port in other places. */
intval
=
150
;
/*Set a PWM value, the maximum value of PWM is 255, but the speed should not
be too fast when tracing the car, otherwise the car will shake more in the tracing process.*/
analogWrite
(
M1
,
0
);
analogWrite
(
E1
,
val
);
//the speed value of motorA is val
analogWrite
(
M2
,
0
);
analogWrite
(
E2
,
val
);
//the speed value of motorB is val
}
else
if
((
right1
<=
8
)
&&
(
centre
>=
975
)
&&
(
left1
>=
975
))
{
/* The value collected to judge,
if the center > = 975 and left1 > = 975 are greater than 975, indicating that the middle and left
sensors did not detect the black line, right1 <= 8 shows the right sensor detects a black line, then
the car Has left to the left, or the black line has been turning to the right, so the car should
turn to the right. */
intval
=
150
;
analogWrite
(
E1
,
0
);
analogWrite
(
M1
,
val
);
//the speed value of motorA is val
analogWrite
(
M2
,
0
);
analogWrite
(
E2
,
val
);
//the speed value of motorB is val
}
else
if
((
right1
>=
975
)
&&
(
centre
>=
975
)
&&
(
left1
<=
8
))
{
/* Judge the collected value, if
center > = 975 and right1 > = 975 are greater than 975, indicating that the middle and right sensors
did not detect the black line, left1 <= 8 shows that the left sensor detects the black line, then
the car Has been to the right deviation, or the black line has turned to the left, so the car should
turn left at this time. */
intval
=
130
;
analogWrite
(
M1
,
0
);
analogWrite
(
E1
,
val
);
//the speed value of motorA is val
analogWrite
(
E2
,
0
);
analogWrite
(
M2
,
val
);
//the speed value of motorB is val
}
if
((
right1
<=
8
)
&&
(
centre
<=
8
)
&&
(
left1
<=
8
))
{
/* The value collected to judge, if the
center <= 8, left1 <= 8 and right1 <= 8 are greater than 8, indicating 3 sensors have detected a
black line, then the car has reached the "ten" intersection, because We have only 3 sensors, no way
to make more sophisticated judgments, so only let the car choose to go straight. */
intval
=
130
;
analogWrite
(
M1
,
0
);
analogWrite
(
E1
,
val
);
//the speed value of motorA is val
analogWrite
(
M2
,
0
);
analogWrite
(
E2
,
val
);
//the speed value of motorB is val
}
}
Summary of Contents for Hummer-Bot-1.0
Page 1: ...Hummer Bot 1 0 Instruction Manual V 2 0 ...
Page 18: ...15 Step4 You need to install motors Figure 3 1 5 Schematic diagram of motor installation ...
Page 50: ...47 Figure 3 2 15 Diagram of Data without Obstacles ...
Page 83: ...80 Test code Path hummer bot Lesson ModuleDemo IrkeyPressed IrkeyPressed ino ...