Lesson 6 – Buzzer + Putting It All Together

Hummingbird Components

2 LEDs (Single Color or Tri-Color), 1 Position Servo, 1 Rotation Servo

Python Concepts

For loops with lists

Teacher Materials

Get Access

In the previous lessons, you have learned to use the Hummingbird lights and motors, as well as the micro:bit display. These are known as the outputs. Python sends commands to these components to make something happen. There is one more output, the buzzer on the Hummingbird board. In this lesson, you will learn to play simple songs using the buzzer. You will also complete a challenge with all of the Hummingbird components you have used so far. This will help you to review all of the Hummingbird outputs so that you are ready to move on to inputs (sensors) in the next lesson.

Use the playNote() function to play a note using the buzzer on the Hummingbird Bit. The method requires a integer representing the note (32-135) and a number giving the number of beats (0-16). The note number is the MIDI number for a particular musical note. For example, middle C is 60. This website may be helpful in matching note numbers to names. The number of beats can be a decimal number. A beat is roughly equal to one second.

Exercise 1

Try out this sample code, and then modify it to play three different notes.

Exercise 2

What is the difference between Example 1 and Example 2? Make a hypothesis, and then test it out.

If you are playing a series of notes, you can use a for loop. Instead of using the range() function, use square brackets to make a list of note numbers.

Exercise 3

Try out this sample code, and then modify it to play a song of your own.

Exercise 4

Now it is time to put all the things you have learned together! Create a display of lights and movement set to music. Your project should include the following:

  • At least two LEDs
  • At least one position servo
  • At least one rotation servo
  • A song played with the buzzer

Extra Challenge

In this lesson, you used for loops with a list of notes, but every note in the loops had the same number of beats. You can also uses lists to vary both the notes and the number of beats for each note. Try out this sample code and experiment with how you can use it to play a song. For some songs to try, see this website (if you read music) or this one (if you don’t).

Back to Top