Sound effects

The next fun thing we'll learn is how to increase and decrease the tone frequency on ByteBoi using two buttons. 

You can open a new sketch, and let's start!

First, you'll need to create a new variable and call it "frequency". 

random image

Place a "set frequency to" block into the "Arduino run first:" branch: 

random image

Find this block named "123" in the "Math" section. , As we mentioned before, this block is a numerical value block, and you can type in the numerical value you want once you drop it onto the drawing area.  

Let's put the frequency value to 1000.

random image

Now that we have a variable created and set to 1000 let's change the variable when a certain event is triggered.

When you press ByteBoi's up and down buttons, we change the variable.

Luckily, we have a specific block defined for that, and it's under the I/O section.
I/O stands for "Input/output". ByteBoi's buttons are the so-called input devices because they send an electrical impulse to ByteBoi's computer when triggered.
ByteBoi's display is an example of an output device because ByteBoi sends signals to it to display information.   

You need to find this purple block named "When button up gets pressed". 

Place the block onto the drawing area.

random image

You can duplicate the purple block.

We will need one of them to increase the tone frequency and the other to decrease it.

random image

Now let's change the variable's value by 100 every time you press ByteBoi's buttons.

This is done by a block "change frequency by".

Place that block into the purple "When button up (down) gets pressed" event block. 

random image

Make sure the value in one block is positive and in the other negative.

The next block we will need is "Play tone with Hz for milliseconds"  from the I/O section.

We'll put the "frequency" variable in the left circle and the number 500 in the right circle.

random image

Now hit the red "Run" button, and don't forget to save your code!

Once your code is compiled, you can press the up button on your ByteBoi and increase the tone frequency or use the down button and decrease it. 

This was fun. Let's see what else we can do.