72
#include <Servo.h>
/* In this section, we use the steering gear, so we need to call the steering gear
library file. As for what is in the library file, we will not study it. Interested friends can drive
for research. We have put this library files on the CD-ROM, we need to copy this folder to the Arduino
IDE installation path "libraries" folder, otherwise the program can not compile. */
Servo head
;
int
E1
=
5
;
//PWMA
int
M1
=
9
;
//DIRA****************************************left
int
E2
=
6
;
//PWMB
int
M2
=
10
;
//DIRB****************************************right
/*Define 4 motor control terminals, connected to IN1-IN4 on the motor drive board. */
const
int
TrigPin
=
2
;
const
int
EchoPin
=
3
;
/* Define the sensor's 2 control pins to connect to pins 2 and 3 on the Arduino.*/
const
int
leftPin
=
A3
;
const
int
rightPin
=
A4
;
float
da
;
float
dl
;
float
dr
;
/* Define three variables, used to store the servo at 0,90,180 degrees, the value collected
by the ultrasonic module, da is the value collected by the ultrasonic 90 degrees servo, dl is the
steering servo 180 degrees ultrasonic acquisition To the value, at this point the steering gear has
turned to the left of the car. da for the servo 0 degrees ultrasonic collected value, then the steering
gear has turned to the right side of the car. */
float
left
;
float
right
;
void
setup
()
{
Serial
.
begin
(
9600
);
/*Set the baud rate to 9600,use "Serial Monitor" to check the data during
debugging*/
head
.
attach
(
13
);
/* Define the control pin of the servo as pin 13*/
pinMode
(
E2
,
OUTPUT
);
pinMode
(
E1
,
OUTPUT
);
pinMode
(
M1
,
OUTPUT
);
pinMode
(
M2
,
OUTPUT
);
pinMode
(
leftPin
,
INPUT
);
pinMode
(
rightPin
,
INPUT
);
pinMode
(
TrigPin
,
OUTPUT
);
pinMode
(
EchoPin
,
INPUT
);
/* Define two ultrasonic working mode. */
head
.
write
(
90
);
/* The servos swivel to 90 (center) during initialization, because 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
()
{
left
=
analogRead
(
leftPin
);
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 ...