@@ -17,7 +17,7 @@ which is lit when the microphone is in use.
1717Sound events
1818============
1919The microphone can respond to a pre-defined set of sound events that are
20- based on the amplitude and wavelength of the sound.
20+ based on the amplitude and wavelength of the sound.
2121
2222These sound events are represented by instances of the ``SoundEvent `` class,
2323accessible via variables in ``microbit.SoundEvent ``:
@@ -33,42 +33,63 @@ Functions
3333
3434.. py :function :: current_event()
3535
36- * **return **: the name of the last recorded sound event,
37- ``SoundEvent('loud') `` or ``SoundEvent('quiet') ``.
36+ Get the last recorded sound event.
37+
38+ :return: The event, ``SoundEvent('loud') `` or ``SoundEvent('quiet') ``.
3839
3940.. py :function :: was_event(event)
4041
41- * **event **: a sound event, such as ``SoundEvent.LOUD `` or
42- ``SoundEvent.QUIET ``.
43- * **return **: ``true `` if sound was heard at least once since the last
44- call, otherwise ``false ``. ``was_event() `` also clears the sound
45- event history before returning.
42+ Check if a sound was heard at least once since the last call.
43+
44+ This call clears the sound history before returning.
45+
46+ :param event: The event to check for, such as ``SoundEvent.LOUD `` or
47+ ``SoundEvent.QUIET ``.
48+ :return: ``True `` if sound was heard at least once since the last call,
49+ otherwise ``False ``.
4650
4751.. py :function :: is_event(event)
4852
49- * **event **: a sound event, such as ``SoundEvent.LOUD `` or
50- ``SoundEvent.QUIET ``.
51- * **return **: ``true `` if sound event is the most recent since the last
52- call, otherwise ``false ``. It does not clear the sound event history.
53+ Check the most recent sound event detected.
54+
55+ This call does not clear the sound event history.
56+
57+ :param event: The event to check for, such as ``SoundEvent.LOUD `` or
58+ ``SoundEvent.QUIET ``
59+ :return: ``True `` if sound was the most recent heard, ``False `` otherwise.
5360
5461.. py :function :: get_events()
5562
56- * **return **: a tuple of the event history. The most recent is listed last.
57- ``get_events() `` also clears the sound event history before returning.
63+ Get the sound event history as a tuple.
64+
65+ This call clears the sound history before returning.
66+
67+ :return: A tuple of the event history with the most recent event last.
5868
5969.. py :function :: set_threshold(event, value)
6070
61- * **event **: a sound event, such as ``SoundEvent.LOUD `` or
62- ``SoundEvent.QUIET ``.
63-
64- * **value **: The threshold level in the range 0-255. For example,
65- ``set_threshold(SoundEvent.LOUD, 250) `` will only trigger if the sound is
66- very loud (>= 250).
71+ Set the threshold for a sound event.
72+
73+ The ``SoundEvent.LOUD `` event will be triggered when the sound level
74+ crosses this threshold upwards (from "quiet" to "loud"),
75+ and ``SoundEvent.QUIET `` event is triggered when crossing the threshold
76+ downwards (from "loud" to "quiet").
77+
78+ If the ``SoundEvent.LOUD `` value set is lower than ``SoundEvent.QUIET ``,
79+ then "quiet" threshold will be decreased to one unit below the "loud"
80+ threshold. If the ``SoundEvent.QUIET `` value is set higher than
81+ ``SoundEvent.LOUD ``, then the "loud" threshold will be set one unit above.
82+
83+ :param event: A sound event, such as ``SoundEvent.LOUD `` or
84+ ``SoundEvent.QUIET ``.
85+ :param value: The threshold level in the range 0-255. Values outside this
86+ range will be clamped.
6787
6888.. py :function :: sound_level()
6989
70- * **return **: a representation of the sound pressure level in the range 0 to
71- 255.
90+ Get the sound pressure level.
91+
92+ :return: A representation of the sound pressure level in the range 0 to 255.
7293
7394
7495Example
@@ -80,7 +101,7 @@ An example that runs through some of the functions of the microphone API::
80101 # Button A is pressed and a loud or quiet sound *is* heard, printing the
81102 # results. On Button B this test should update the display when a loud or
82103 # quiet sound *was* heard, printing the results. On shake this should print
83- # the last sounds heard, you should try this test whilst making a loud sound
104+ # the last sounds heard, you should try this test whilst making a loud sound
84105 # and a quiet one before you shake.
85106
86107 from microbit import *
0 commit comments