Let's learn what to do with the buzzer soldered to your CircuitPet.
As the word itself says, the buzzer is used to make buzzing sounds.
We'll make a very similar sketch to the last one, but this time, pressing the buttons will trigger a particular sound to come out of the buzzer.
For the beginning, go to the Display section and select the "set font size to" block.
As with the previous two sketches, we'll change the font size to 1.
The next thing to do is choose a font type, another block in the Display section.
Click on the block and drag it into the drawing area.
And now, let's set the font color.
This time we choose our font to be yellow.
Now that we've created a font let's change what happens with the buzzer when a specific button is pressed or released.
As in the previous sketch, we'll use I/O blocks to determine what happens when specific buttons are pressed.
Let us introduce you to a new block called "Play tone with frequency 1000 Hz for 500 milliseconds".
Click on the block, and drag it into the I/O block in the drawing area
We changed the milliseconds to 200, but you can make it as long or as short as you like.
Let's clear the display in purple once we press the right button.
You can choose what will be written on the display once the button is pressed.
For example, the screen can say "boop" when we press the right button.
Don't forget about the coordinates!
Let's make "x" 65 and "y" 60.
And for the end, drag the "draw sprite to display" block for a sketch to work.
First button - DONE!
Since we'll need the same blocks, we can easily duplicate them.
Let's do one button at a time.
The first one we'll do is for when a left button gets pressed. We decided to play tone with a frequency of 2000 Hz this time, but we kept the same amount of time we'll play that tone for.
The screen's color stays purple, but we'll print "Beep" this time.
Let's duplicate the block again.
Now, we'll use a button for going back and playing tone with a frequency of 3000 Hz for 50 milliseconds.
In the meantime, on the screen will be written "Ding". Note that we kept coordinations the same for all prints.
Yes, you guessed it right!
It's time to duplicate some more blocks.
The last button we'll use is the enter one. In this sketch, we won't do anything with releasing this button.
If you press the enter button, the buzzer will play tone with a frequency of 100 Hz for 150 milliseconds.
While the tone is playing, the screen will say "Buzz".
Great! We used all of the four buttons from CircuitPet.
We should do something with the screen once CircuitPet turns on.
The best thing we can do is write what will happen next on the screen.
To do so, we'll need to jump to the Display section and use a couple of blocks.
The first thing we want to do is clear the display so that the text can be transparent.
To do so, use this block:
This block needs to be dragged to the Arduino run first block section.
Since we cleared the display, it's time to write something on it.
Drag a circled block in the Arduino run first section.
Also, you'll need two of these blocks so the text is nicely placed in the middle of the screen.
So, the text that will be written on display once you turn your CircuitPet on will say, "Press one of the buttons!".
Basically, this is like an on-screen guide.
And, we hope you know what must be placed at the end of every sketch. The "draw sprite to display" block!
You did it!
Hit the big red Run button, wait for a code to compile, and check it out.
Once the code is compiled, your CircuitPet should restart, and the screen will turn yellow with the purple sign saying, "Press one of the buttons!".