精品导航

Sound on

Let's learn what to do with the Piezo buzzer that's soldered onto your 手机在线电影.

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!

Go to the display block section and choose the "fill frame with" block.

random image



Now we'd like to write the instructions that are shown as soon as we press the Run button.

We'll need the "write string" block for that. You can find it here:

random image
random image



We'll make the background white and write "Press the buttons" in black, as shown in the image above.

We don't want to forget about the "push frame" block.
Amazing! You can test your code by clicking Run, and then proceed with the sketch and change what happens when a particular event is triggered.
When you press 手机在线电影's buttons, we trigger a particular event.
As we learned in the previous chapter, a specific block defined for that can be found under the I/O section.
The first block from the I/O section we'll use is "when left pressed".

random image



Drag and drop it under the instructions part of the code. 

random image



This time, we want a buzzer to make a specific sound and draw one of the shapes from the first chapter.

To do so, we'll need to begin with another I/O block, "play tone (0,0)".
This block will be used to specify the frequency and duration of our sound.

random image



Drag it into the I/O block, change the frequency to 1000 Hz, and play it for 200 milliseconds.

random image



Amazing! 

Let's try something similar to what we did in the previous example.
Because we'll be drawing something on the screen, we'll need to fill the screen with the particular color, which you can do by locating the "fill frame" block.

random image
random image



We must now decide what we want to draw, whether it will be filled or outlined, and where we want it to be drawn.

We can do that using this block: 

random image
random image



We chose to draw a 6x6 filled red rectangle at the coordinates 40x50.

Finally, at the end of this block, insert the "push frame" block.

random image



Before we can test whether pressing this specific button causes the desired event, we must first find the "loop forever" block to ensure that your buttons are being scanned at all times. Please remember to use this every time you code something with the buttons, or it will not work.

The "loop forever" button can be found here:

random image



Drag and drop it on the drawing area and look for the I/O "scan buttons" block:

random image
random image



You can now test everything by pressing the Run button and then clicking on left button.

When you press that button, your screen should look like this, and you should hear a sound from your 手机在线电影:
Now, just like in the previous sketch, we'll duplicate this for the three more buttons and change them slightly.
To begin, double-click the I/O block that says "when left pressed" to duplicate everything inside it.

random image



This new I/O block will alter what happens when we press the right button.
Now, we'll play the sound at 2000 Hz for 200 milliseconds.

At the same time, we'll draw a 6x6 blue-filled rectangle with coordinates 40x50 on a yellow background.
To see what happens, click the Run button and then the left button on your 手机在线电影:
Let's do it again with another button.

random image



This time, we'll trigger the event pressing the enter button.

The sound will play at 100 Hz for 150 milliseconds, and we will draw a 6x6 yellow-filled rectangle on a purple background with coordinates 40x50.
To see what happens, click the Run button and then enter:
Finally, we'll repeat this process for the back button.

random image



The sound will play for 50 milliseconds at 3000 Hz, and we will draw a white filled rectangle 6x6 in the coordinates 40x50 on the marron background.

Now that you know how to make sounds and draw different things, you can experiment with the buzzer and the display.

友情链接:久久久久久 | 欧美午夜 | 蘑菇网页版入口 | tsxhyq.com | 在线午夜 | lf397.com | 屁屁影院 | 久久爱 | hebeijiaoyuwang.com | 伊人色 | 小草社区 | 小蓝视频 | 在线亚洲 | 玖玖爱 | 蘑菇短视频入口 | 无名网 | 午夜在线观看 | 青草青青 | 宅男影院 | 五月丁香 | 日本高清 | 秋霞网 | tissu-premier.com | 色妞 | dna0126.com | 琵琶妞 | 色啪 | btupic.com | 蘑菇传媒在线观看 | 番号网 | 蘑菇网 | bt搜索 | 汤姆影院 | mogutv | 福利精品 | 蓝色导航 | 蘑菇影视 | 久久香蕉 | 玖玖资源站 | 导航大全 | 蘑菇tv网页版 | 青娱 | 永久网站 | 福利盒子 | rencai98.com | 色婷婷 | 蘑菇视频ios | 龙物视频 | 亚洲精品 | 天天综合 | sanzhucare-zhpg.com | fltou.com | mogu视频 | 蘑菇传媒 | 资源导航 | 永久地址 | 秋霞影院 | 最新av | 蘑菇在线观看网页版 | woqidz.com | 看片神器 | 蘑菇视频网站 | 4008108885.com | 老司机视频 | 超碰视频 | 扒哥黑料 | zhuoyemall.com | 协和影院 | 四虎影视 | jxty00.com | 蘑菇视频入口 | 迷妹网 | 蜜芽视频 | p站视频 | 老王影院 | 蘑菇app | 六月婷婷 | 综合影院 | 天堂在线 | 亚洲网 | 青青伊人 | 樱花视频 | 青草草 | dk99999.com | 第一福利 | 摩天轮社区 | mogu | 精品免费 | zpzb2008.com | 五福影院 | gzdksw.com | 久久视频 | 蘑菇視頻 | 酒色世界 | mogus.cc | 草莓视 | 红桃视频 | 琳琅导航 | 性知音