pxt-calliope/docs/reference/input/set-sound-threshold.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

1.5 KiB

set Sound Threshold

Tell how loud it should be for your board to detect a loud sound.

input.setSoundThreshold(SoundThreshold.Loud, 0)

When the microphone hears a sound, it sets a number for how loud the sound was at that moment. This number is the sound level and has a value from 0 (low sound) to 255 (loud sound). You can use a sound level number as a threshold (just the right amount of sound) to make the on sound event happen. To set a threshold, you choose the type of sound to detect, loud or quiet, and then the sound level for that type.

~ reminder

works with micro:bit V2 only image

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 dectect: loud or quiet.
  • threshold: the sound level number which makes a sound event happen.

Example #example

Show an icon animation when the microphone detects a sound louder than a sound level of 200.

input.setSoundThreshold(SoundThreshold.Loud, 200)
input.onSound(DetectedSound.Loud, function () {
    basic.showIcon(IconNames.Square)
    basic.showIcon(IconNames.SmallSquare)
    basic.showIcon(IconNames.SmallDiamond)
    basic.clearScreen()
})

See also #seealso

on sound, sound level

microphone