5f7a8e5301
* update yotta defaults for 16kb devices * refactor deprecated blocks * updates for button events * update button events * update refference * update docs * update docs * update button event blocks * update docs * update block id
1.1 KiB
1.1 KiB
on Sound
Run some code when the microphone hears a sound.
input.onSound(DetectedSound.Loud, function () {})
The microphone will detect sounds that are quiet or loud. You can have the microphone detect
a sound at a certain level and run some code in and event when it hears the sound. There are
two sound ranges you can detect for: loud
or quiet
.
~ reminder
This block requires the micro:bit V2 hardware. If you use this block with a micro:bit v1 board, you will see the 927 error code on the screen.
~
Parameters
- sound: the type of sound to detect:
loud
orquiet
. - handler: the code to run when a sound is heard.
Example
Show an icon animation when the microphone detects a sound.
input.onSound(DetectedSound.Loud, function () {
basic.showIcon(IconNames.Square)
basic.showIcon(IconNames.SmallSquare)
basic.showIcon(IconNames.SmallDiamond)
basic.clearScreen()
})
See also #seealso
sound level, set sound threshold
microphone