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.
Lesson 6 – Buzzer + Putting It All Together
2 LEDs (Single Color or Tri-Color), 1 Position Servo, 1 Rotation Servo
For loops with lists
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.
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
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).