Buzz around!

Buzz around!

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.


Let's start!

For the beginning, go to the Display section and select the "set font size to" block.

random image

As with the previous two sketches, we'll change the font size to 1.

random image

The next thing to do is choose a font type, another block in the Display section.

random image

Click on the block and drag it into the drawing area.

random image

And now, let's set the font color.

random image

This time we choose our font to be yellow.

random image

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.

random image

random image

Let us introduce you to a new block called "Play tone with frequency 1000 Hz for 500 milliseconds".

random image

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.

random image

Let's clear the display in purple once we press the right button.

random image

  You can choose what will be written on the display once the button is pressed.

random image

random image

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.  

random image

First button - DONE!

random image

Since we'll need the same blocks, we can easily duplicate them.

Let's do one button at a time.

random image

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.  

random image

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".  

random image

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:   

random image

This block needs to be dragged to the Arduino run first block section.

random image

Since we cleared the display, it's time to write something on it.

random image

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.  

random image

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!  

random image

You did it! 


Congrats!

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!".