The Circuit Playground Express has a real speaker! It’s not going to compete with your HiFi stereo, but it can play simple songs and tones.
In this exercise, we will add two sound clips to the board.
To access the speaker, we will need to import the module:
from adafruit_circuitplayground.express import cpx
adafruit_circuitplayground.express file, we can play audio using the
cpx.play_file() function. The name of the audio file will go inside the parentheses like so:
In this exercise, let’s output some sound by clicking button A and button B.
Here are some sound clips from Super Mario Bros:
Note: To preview the sound clips, right-click the links above and choose to open the link in a new tab or window.
Download two of the sound files above (right-click and press “Save Link As…”).
And store them in the CIRCUITPY drive:
cpx.button_ais pressed, play 1st clip by using
cpx.button_bis pressed, play 2nd clip by using
Click the Download button to download the code.py file.
Drag and drop the downloaded file into the CIRCUITPY drive on your computer.
Press button A and then press button B. Are there any sounds?
Press Run again when you are ready to move on.