Generate tones using the onboard buzzer
- generating square waves
For this example, we use the piezo buzzer wired to pin 25 of the Magicbit.
We could specify the frequency & duration of the tone with the “play tone, [Frequency] Hz, duration: [Duration] ms” block.
Drag and drop the following blocks from the block palette and create the following script.
This program starts by clicking the green flag. The forever block continuously runs the code held inside the block. Frequencies 4186 Hz and 5274 Hz represent C and E notes, respectively. This program plays note C for 500ms and after that plays E note 500 ms continuously.” play tone, [Frequency] Hz, duration: [Duration] ms” block generates PWM corresponding to the given parameters.
Note: Create a program that plays one frequency when one push button on the board is pressed, and another frequency when the other push button when pressed.