Using the Speaker

header-lesson-02

Using the Speaker#

This section will focus on the speaker or buzzer on the micro:bit to play a built-in melody. The speaker is more like a primitive speaker (a piezoelectric buzzer) on an old PC. It will not play the range of sounds a regular speaker will play, but it is works for most projects.

microbit-buzzer

Select the “Music” drawer in the Toolbox.

makecode-music-01

This drawer has many blocks that can be used to code the speaker. You can play specific tones, create melodies and change the volume. We will focus on playing a built-in melody.

makecode-music-02

Scroll down and find the play <melody dadadum> block. Make sure to scroll down and select this block. The other play block closer to the top is used for custom melodies.

makecode-music-03

Place the play block in the forever block.

makecode-music-04

Choose the dropdown menu to choose any of the built-in melodies.

makecode-music-05

In this example, melody nyan is selected.

makecode-music-06

The micro:bit is now ready to be flashed with code. Press the download button to transfer the code to the micro:bit.