Stop melody all:
Stop playing a musical melody.
We can use this block to stop melodies that are
played either in the foreground or background. In
this case, if the value of dis more than 10, we use
this block to stop melody immediately.
Blocks overview
1. Add extension package for the ultrasonic
ranging sensor.
2. Set a variable named dis to store the distance detected by
the ultrasonic ranging sensor.
3. Read the distance in cm from ultrasonic and store in dis.
4. If the value of “dis” less than 10, show “heart” icon on
matrix LEDs, play a melody and turn two LEDs on.
Have you ever seen a robot that says hello when someone approaches? That is a very interesting
thing
,
so let's do a similar project in this lesson, put it in a box and make a fun and smart music
box!
Experiment 18 – Smart music box
Instruction
Connect Crowtail-Ultrasonic Ranging Sensor to P13&P15
port of Crowtail-Base shield for Micro:bit. Connect
Crowtail-Buzzer, Crowtail-LED(Green) and Crowtail-LED
(Yellow) to P0, P1 and P2 ports of Crowtail-Base shield for
Micro:bit. The hardware connection are as follows:
Use the modules and programming knowledge we have learned to make a smart music box.
Learn how to stop the buzzer melody.
Target
Micro:bit x1
Crowtail-Base shield for Micro:bit x1
Crowtail-Ultrasonic Ranging Sensor x1
Crowtail-Buzzer x1
Crowtail-LED(Green) x1
Crowtail-LED(Yellow) x1
Crowtail-Cable x4
USB cable x1
Required Parts
Hardware learning and connection
Programming and note
43