
MagicCode Lesson 8
Generate tones using the onboard buzzer
Components Required
Introduction
Learning Outcomes
- genearting square waves
Theory
Methodology
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 “play tone, [Frequency] Hz, duration: [Duration] ms” block.
Drag and Drop following blocks from block palette and create the following script.
Script
Explanation
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 play note C for 500ms and after that play 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 pressed, and another frequency when the other push button when pressed.