The built-in speaker is not only capable of playing sound files; it can also play basic tones with the
For example, the code below would play the middle C note for
cpx.play_tone() requires two things:
- The frequency of the tone (Hz)
- The duration of the tone (sec)
Let’s try it out.
cpx.button_ais pressed, play a tone by using
cpx.button_bis pressed, play a tone by using
You can choose any frequencies between
1000, each for as many seconds as you like.
Click the Download button to download the code.py file.
Drag and drop the downloaded file into the CIRCUITPY drive on your computer.
Now, press each button. Each one should play a tone!