41
STEP1:
Plug the Crowtail-Motor Base Shield onto the Arduino or Crowduino board.
Hardware Connection
STEP2:
Connect Crowtail-OLED to A4&A5
port of Crowtail-Motor Base Shield.
Connect Crowtail-Ultrasonic Ranging
Sensor to D2&D3 port of Crowtail-Motor
Base Shield. Connect the two Micro-Speed
Motor to the motor interface of Crotail-
Motor Base Shield. The OUT1 and OUT2
interfaces are connected to the same motor
positive and negative poles, and the OUT3
and OUT4 interfaces are connected to the
same motor positive and negative poles.
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
P19_A_Naughty_Robot
with
Arduino and upload it.
If there is nothing in front of the ultrasonic ranging sensor, the two micro-speed motors will always run,
and a smiling face will be displayed on the OLED, just like a naughty robot. Put your hand or other
obstacles in front of the ultrasonic ranging sensor, you will stop the two micro-speed motors and an
angry expression will be displayed on the OLED.
What will you see
1. Import the I2C, ultrasonic ranging sensor and OLED libraries.
2. Create an instance object for ultrasonic ranging sensor and OLED.
3. Declare the bitmap of a happy and angry image.
4. Declare some variables for the motor pin and ultrasonic ranging sensor.
5. Setup all the pins of the motor as output.
6. Create functions to control the motor and draw images on OLED.
7. Read the value of the distance from the ultrasonic ranging sensor.
8. If the distance’s value lower than 10 cm, draw an angry image and make the two motors stop.
9. If the distance’s value more than 10 cm, draw a smile image and make the two motors keep running.
Code overview
Summary of Contents for Crowtail Deluxe Kit
Page 47: ......