@@ -26,7 +26,9 @@ accessible via variables in ``microbit.SoundEvent``:
26
26
from ``loud `` to ``quiet `` like speaking or background music.
27
27
28
28
- ``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.
30
32
31
33
Functions
32
34
=========
@@ -35,16 +37,17 @@ Functions
35
37
36
38
Get the last recorded sound event.
37
39
38
- :return: The event, ``SoundEvent('loud') `` or ``SoundEvent('quiet') ``.
40
+ :return: The event, ``SoundEvent('loud') ``, ``SoundEvent('quiet') `` or
41
+ ``SoundEvent('clap') ``.
39
42
40
43
.. py :function :: was_event(event)
41
44
42
45
Check if a sound was heard at least once since the last call.
43
46
44
47
This call clears the sound history before returning.
45
48
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 `` .
48
51
:return: ``True `` if sound was heard at least once since the last call,
49
52
otherwise ``False ``.
50
53
@@ -54,8 +57,8 @@ Functions
54
57
55
58
This call does not clear the sound event history.
56
59
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 ``.
59
62
:return: ``True `` if sound was the most recent heard, ``False `` otherwise.
60
63
61
64
.. py :function :: get_events()
@@ -68,7 +71,7 @@ Functions
68
71
69
72
.. py :function :: set_threshold(event, value)
70
73
71
- Set the threshold for a sound event .
74
+ Set the threshold for the `` LOUD `` or `` QUIET `` sound events .
72
75
73
76
The ``SoundEvent.LOUD `` event will be triggered when the sound level
74
77
crosses this threshold upwards (from "quiet" to "loud"),
@@ -80,8 +83,7 @@ Functions
80
83
threshold. If the ``SoundEvent.QUIET `` value is set higher than
81
84
``SoundEvent.LOUD ``, then the "loud" threshold will be set one unit above.
82
85
83
- :param event: A sound event, such as ``SoundEvent.LOUD `` or
84
- ``SoundEvent.QUIET ``.
86
+ :param event: A ``SoundEvent.LOUD `` or ``SoundEvent.QUIET `` event.
85
87
:param value: The threshold level in the range 0-255. Values outside this
86
88
range will be clamped.
87
89
@@ -111,7 +113,10 @@ An example that runs through some of the functions of the microphone API::
111
113
112
114
while True:
113
115
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:
115
120
display.show(Image.SQUARE)
116
121
uart.write('isLoud\n')
117
122
elif microphone.current_event() == SoundEvent.QUIET:
@@ -120,7 +125,10 @@ An example that runs through some of the functions of the microphone API::
120
125
sleep(500)
121
126
display.clear()
122
127
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):
124
132
display.show(Image.SQUARE)
125
133
uart.write('wasLoud\n')
126
134
elif microphone.was_event(SoundEvent.QUIET):
@@ -135,7 +143,9 @@ An example that runs through some of the functions of the microphone API::
135
143
soundLevel = microphone.sound_level()
136
144
print(soundLevel)
137
145
for sound in sounds:
138
- if sound == SoundEvent.LOUD:
146
+ if sound == SoundEvent.CLAP:
147
+ display.show(Image.DIAMOND)
148
+ elif sound == SoundEvent.LOUD:
139
149
display.show(Image.SQUARE)
140
150
elif sound == SoundEvent.QUIET:
141
151
display.show(Image.SQUARE_SMALL)
0 commit comments