In this project, we introduce the sound functions and use them to play notes through the speaker.

The assembled CREATOR Kit has an attached speaker and audio cable, and also a set of functions that allow you to play notes, music and sound effects.

If your audio cable was removed, reattach it now:

  1. Insert the Audio Cable into the audio jack on the Raspberry Pi.

  2. Connect the other end of the Audio Cable to the Speaker Cable (the cable attached to the Speaker Assembly). Note: It doesn't matter which way the three-pronged Audio Cable is oriented.

With the speaker hardware connected, we can start making noise with just a few lines of code...

In this project, we're just going to use the basic functionality of the sound functions to play notes of different durations. Let's start with this code:

If you run this code, you'll hear a single tone play for one second. Here's how this simple four-line program works:

If you want to change the duration of the note, you can set duration in the play() function, like this:

  1. What happens if you don't wait() for the sound to finish playing? Why?

  2. If you play two of the same notes in a row for 1 second each, does it sound the same as if you play the one note for 2 seconds?

  3. Can you play a rhythm, like the "Shave and a haircut" door knock?