12
Be careful not to connect the motor to the interval interface, such as OUT1 and OUT3, otherwise, the
motor will not work properly. The complete connection is as follows.
Note: Because the motor consumes more power, after uploading the code, you need to provide additional
power for the Crowtail-Motor Base Shield (usually connect 9V power supply for the power input port of the
motor base shield) and then turn on the onboard power switch(you don’t have to power Crowduino/Arduino,
because the motor base shield will share the power with Crowduino/Arduino).
Open the
P04_Motor_Control
with Arduino IDE and upload it.
Assume that motors 1 connected to OUT1 and OUT3 are mounted on the left tire of the car, and
motors 2 connected to OUT3 and OUT4 are mounted on the right tire of the car. At the beginning,
you will see that motor 1 is faster than motor 2 so that the car can turn left. Then, the two motors
stopped rotating for two seconds. Finally, the motor1 motor is slower than the motor2 motor. This
way the car can turn right.
What will you see
1. Declare the pins to control the speed and direction of rotation of the two motors.
2. Setup the pins which are used to control motors as output.
3. Create three functions to control the two motors to turn left, turn right and stop.
4. Call left, stop and right functions we just created to control motor rotation.
Code overview
Code usage
'const' is the abbreviation of constants. Here, we will create 6 constant which mean the pins we use
to control the two motors. You can control the steering and speed of the motor through our motor
control usage chart.
Constant: const int pinI1=8; const int pinI2=11; const int speedpinA=9; const
int pinI3=12; const int pinI4=13; const int speedpinB=10;
Modular programming allows us to better manage and call our code, such as a module code
problem, we only need to modify the code inside the module, without modifying the code of the entire
program. In addition, modularizing the code allows us to implement functions with simpler logic. We
call these three functions in the loop() function to control the motor to turn left, stop and turn right.
Modular programming: void Test_Load_Left(){}
void Test_Load_Right(){}
void clean_Output(){}
Summary of Contents for Crowtail Deluxe Kit
Page 47: ......