@@ -26,7 +26,9 @@ accessible via variables in ``microbit.SoundEvent``:
2626 from ``loud `` to ``quiet `` like speaking or background music.
2727
2828- ``microbit.SoundEvent.LOUD ``: Represents the transition of sound events,
29- from ``quiet `` to ``loud `` like clapping or shouting.
29+ from ``quiet `` to ``loud `` like shouting.
30+
31+ - ``microbit.SoundEvent.CLAP ``: Detects a loud event similar to a clap.
3032
3133Functions
3234=========
@@ -35,16 +37,17 @@ Functions
3537
3638 Get the last recorded sound event.
3739
38- :return: The event, ``SoundEvent('loud') `` or ``SoundEvent('quiet') ``.
40+ :return: The event, ``SoundEvent('loud') ``, ``SoundEvent('quiet') `` or
41+ ``SoundEvent('clap') ``.
3942
4043.. py :function :: was_event(event)
4144
4245 Check if a sound was heard at least once since the last call.
4346
4447 This call clears the sound history before returning.
4548
46- :param event: The event to check for, such as ``SoundEvent.LOUD `` or
47- ``SoundEvent.QUIET ``.
49+ :param event: The event to check for, such as ``SoundEvent.LOUD ``,
50+ ``SoundEvent.QUIET `` or `` SoundEvent.CLAP `` .
4851 :return: ``True `` if sound was heard at least once since the last call,
4952 otherwise ``False ``.
5053
@@ -54,8 +57,8 @@ Functions
5457
5558 This call does not clear the sound event history.
5659
57- :param event: The event to check for, such as ``SoundEvent.LOUD `` or
58- ``SoundEvent.QUIET ``
60+ :param event: The event to check for, such as ``SoundEvent.LOUD ``,
61+ ``SoundEvent.QUIET `` or `` SoundEvent.CLAP ``.
5962 :return: ``True `` if sound was the most recent heard, ``False `` otherwise.
6063
6164.. py :function :: get_events()
@@ -68,7 +71,7 @@ Functions
6871
6972.. py :function :: set_threshold(event, value)
7073
71- Set the threshold for a sound event .
74+ Set the threshold for the `` LOUD `` or `` QUIET `` sound events .
7275
7376 The ``SoundEvent.LOUD `` event will be triggered when the sound level
7477 crosses this threshold upwards (from "quiet" to "loud"),
@@ -80,8 +83,7 @@ Functions
8083 threshold. If the ``SoundEvent.QUIET `` value is set higher than
8184 ``SoundEvent.LOUD ``, then the "loud" threshold will be set one unit above.
8285
83- :param event: A sound event, such as ``SoundEvent.LOUD `` or
84- ``SoundEvent.QUIET ``.
86+ :param event: A ``SoundEvent.LOUD `` or ``SoundEvent.QUIET `` event.
8587 :param value: The threshold level in the range 0-255. Values outside this
8688 range will be clamped.
8789
@@ -111,7 +113,10 @@ An example that runs through some of the functions of the microphone API::
111113
112114 while True:
113115 if button_a.is_pressed():
114- if microphone.current_event() == SoundEvent.LOUD:
116+ if microphone.current_event() == SoundEvent.CLAP:
117+ display.show(Image.DIAMOND)
118+ uart.write('isClap\n')
119+ elif microphone.current_event() == SoundEvent.LOUD:
115120 display.show(Image.SQUARE)
116121 uart.write('isLoud\n')
117122 elif microphone.current_event() == SoundEvent.QUIET:
@@ -120,7 +125,10 @@ An example that runs through some of the functions of the microphone API::
120125 sleep(500)
121126 display.clear()
122127 if button_b.is_pressed():
123- if microphone.was_event(SoundEvent.LOUD):
128+ if microphone.was_event(SoundEvent.CLAP):
129+ display.show(Image.DIAMOND)
130+ uart.write('wasClap\n')
131+ elif microphone.was_event(SoundEvent.LOUD):
124132 display.show(Image.SQUARE)
125133 uart.write('wasLoud\n')
126134 elif microphone.was_event(SoundEvent.QUIET):
@@ -135,7 +143,9 @@ An example that runs through some of the functions of the microphone API::
135143 soundLevel = microphone.sound_level()
136144 print(soundLevel)
137145 for sound in sounds:
138- if sound == SoundEvent.LOUD:
146+ if sound == SoundEvent.CLAP:
147+ display.show(Image.DIAMOND)
148+ elif sound == SoundEvent.LOUD:
139149 display.show(Image.SQUARE)
140150 elif sound == SoundEvent.QUIET:
141151 display.show(Image.SQUARE_SMALL)
0 commit comments