Buzzzzzer

Let's learn what to do with the Piezo buzzer you soldered onto your Chatter.

As the word itself says, the buzzer is used for making 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 click on the "set font size to" block.

random image

We'll also change the font size to 1 here, as we did for the last two sketches.

random image

The next thing to set is a font type, another block that you can find in the Display section as well.

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 have a font created let's change what happens with the buzzer when a certain button gets pressed or released.

Like in the previous sketch, we'll use blocks from the I/O section to determine what'll happen when specific buttons get pressed.

random image

random image

Let's 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 on the drawing area.

We changed the milliseconds to be 200, but you can make it however long or short you want to.

random image

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

random image
random image

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

random image

For example, the screen can say "boop" when we press the right button.

random image

Don't forget about the coordinates! 

Let's make x be 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 used 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". 

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 the first row on Chatter.

We should do something with the screen once Chatter 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 Chatter on will say, "Press one of the top row 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 Chatter should restart, and the screen will turn yellow with the purple sign saying "Press one of the top row buttons!".

If you proceed with the command you got and click on one of the buttons, the sounds will start playing from the buzzer. Depending on the button you clicked on, the tone frequency will be different, and the duration of the tone will change. 

Also, each button will trigger another text written over the display. 

You can check what the screens should look like in the photos below: 

random image
random image
random image
random image
random image