Keywish Hummer-Bot-2.0 Instruction Manual page 63

Table of Contents

Advertisement

the printed value is analog that, the high level is reaching 1024, the low level is 0. After we master the
working principle of the sensor, our tracing car in this section comes to an end, then let us open a car
journey.
3.2.3.6Software Design
3.2.3.6.1 Program flow chart
When the car enters the tracing mode, it keeps scanning the I/O port of the MCU connected to the
sensors, once detecting the changes in signal at the I/O port, the corresponding procedure will be
implemented, the corresponding signal will be sent to the motor so as to correct the status of the car.
When the car enters the tracing mode, it keeps scanning the I/O port of the MCU
connected to the sensors, once detecting the changes in signal at the I/O port, the corresponding procedure
will be implemented. If the left sensor detects the black line (the left half of the car walked across the black
line, the car body is trended right), the car should turn the left; If the right sensor detects the black line (the
right half of the car walked across the black line, the car body is trended left), the car should turn the right.
After the direction adjustment, the car walks forward, and continues to detect the black line repeatedly
3.2.3.6.2 Program Code
#define INPUT1_PIN 6
#define INPUT2_PIN 10
#define INPUT4_PIN 9
#define INPUT3_PIN 5
/*Define 4 motor control terminals, connected to IN1-IN4 on the motor drive board.*/
void
setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
void
loop()
{
int
left1, centre, right1;
left1
=
digitalRead
centre
=
digitalRead
right1
=
digitalRead
if
((right1
== 1) &&
right1 > the sensor captures a value that is low and reads 0 after analog IO. However, to
reduce the error, we set the threshold In 8, to prevent the error caused by the car to
determine the wrong, we can
// PWMB
// DIRB --- right
// PWMA
// DIRA --- left
/*Set the baud rate to 9600 */
/*Define 3 sensors */
(A0);
(A1);
(A2);
/*Read the value collected by 3 sensors */
(centre
== 0) &&
(left1
== 1))
{/* Judge the collected value, if
60

Advertisement

Table of Contents
loading

Related Products for Keywish Hummer-Bot-2.0

Table of Contents