Sound gradient

7,327
Author: Yisong Xu, Si Xu

The onboard buzzer plays a tone rising sound.

Hardware requirements:

mBot/mCore Control Panel

Implementation:

Upload the program to Arduino

Example program download:

Sound gradient.sb2

download

Example programs
scratch 2.0


Script description
In our life, we often hear some regular frequency sounds, like the sound when we pour water into a bottle, when we can hear the tone rising. If the tone is changing between some frequencies (such as an ambulance, which has only two frequencies, high and low), we can directly define the frequency value in the tone-playing block. But if the frequency magnititude is small but its range is wide, this method will cause a very long program. So we can use a “variable” block to make a program where these values vary regularly.

scratch 2.0 Define Variable scratch 2.0 button to the frequency value of a tone and set the duration to 50ms.
scratch 2.0 Define the initial value of Variable  scratch 2.0 button  is 500
Set the varied value of Variable scratch 2.0 button and increase it by 20 each time
scratch 2.0 Set the number of times when Variablescratch 2.0 button  changes to 50


Knowledge points

Point 1 How to define Variable 
in  the block area. Click   to create a variable free. Enter the name of the variable and create it, 4 blocks relating to it will appear automatically, as shown in the following picture.
scratch 2.0 button
The first two blocks are used to define the variable value and the varied value of the variable. The other two blocks are mostly used for stage creation model.
Also on the left upper corner of the mBlock stage, there will be , where the number is the variable value. This is to facilitate users’ observation of the variable value changing.

Point 2 Use of Variable Block
Variables, as we know, are values changing when a program runs. A variable has a name and a value. In mBlock, we can image that a variable is a box containing data. A program can store and extract the data within the box. The name of the box is “variable name” and the data in the box is “variable value”. When you create a variable, the box is empty. When you set a variable value, you fill the box with data. When you change the value you take the data out and put into new data.
The logic of this example is as follows  :
1) Define and create a variable  .
2) Use the block scratch 2.0 button to set the initial value of  to 500.
3) Use the block scratch 2.0 button to define Variable  to the frequency value of the buzzer.
4) Use Block scratch 2.0 button to increase the value of Variable  by 20 each time, i.e. the frequency of the buzzer increases by 20Hz each time.
5) Finally use scratch 2.0 button to limit the number of changes of  to 50, and the final value of  is 500+20*50=1500Hz.
The buzzer sound effects of this example is: It first sounds 500Hz and then the frequency increases by 20Hz each time, i.e. the buzzer sounds respectively 500Hz, 520Hz, and 540Hz … (you can observe the change of the value in  under online debugging status), and each sound lasts for 50ms. It will stop sounding upon the 50th frequency increase.
Note: If change the value in  to -20, the value of  will be decreased by 20 each time.


Extended tasks

Task 1 Let the buzzer play a frequency-decreasing sound
Task 2 Please think what frequency of the last sound made by the buzzer is in this example?


Attached
 -mCore main control board buzzer and onboard button diagram

scratch 2.0

 

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

—— More examples