PWM - Play music
- Ameba x 1
- Buzzer x 1
We use PWM to output sound wave with different frequency, so as to play music by the buzzer.
Connect the buzzer to the PWM output pin:
Below is the RTL8710 Wiring Diagram:
“Examples” -> “AmebaAnalog” -> “TonePlayMelody”
Compile and upload to Ameba, press the reset button. Then you can hear the buzzer playing music.
In the sample code, we initiate a melody array, which stores the tones to make. Another array, noteDurations, contains the length of each tone, 4 represents quarter note (equals to 3000ms/4 = 750ms, and plus an extra 30% time pause), 8 represents eighth note.