pxt-calliope/docs/reference/input/on-sound.md
Juri Wolf 5f7a8e5301
Updates for V4 (#197)
* 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
2022-08-10 09:36:19 -07:00

47 lines
1.1 KiB
Markdown

# on Sound
Run some code when the microphone hears a sound.
```sig
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
![works with micro:bit V2 only image](/static/v2/v2-only.png)
This block requires the [micro:bit V2](/device/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` or `quiet`.
* **handler**: the code to run when a sound is heard.
## Example
Show an icon animation when the microphone detects a sound.
```blocks
input.onSound(DetectedSound.Loud, function () {
basic.showIcon(IconNames.Square)
basic.showIcon(IconNames.SmallSquare)
basic.showIcon(IconNames.SmallDiamond)
basic.clearScreen()
})
```
# See also #seealso
[sound level](/reference/input/sound-level),
[set sound threshold](/reference/input/sound-level)
```package
microphone
```