In the final section of this chapter, we will walk through an example of how to make simple sound and music with PWM. Our sample program is going to play a musical scale on the buzzer, and we will be using a music score format called Ring Tone Text Transfer Language (RTTTL), which was developed by Nokia in the pre-smartphone era for creating ringtones. As we learn, we can use a simple Python library to parse an RTTTL music score and turn its notes into a PWM frequency and duration that can then be used to associate a buzzer to create an auditable tune.
To make a sound with PWM, we need a form of a speaker, and we will be using what is known as a passive buzzer. Buzzers come in two basic forms:
- Active buzzers: These buzzers contain an internal oscillator that generates a single set tone. All you need to do us apply a DC voltage to an active buzzer and it will make a noise.
- Passive buzzers: These do not contain any internal smarts to make...