Microphone
The mPython Board has an onboard microphone that can be used to sense changes in the ambient sound.
Example: display the sound value
from mpython import *
from lv_gui import *
gui = GUI()
while True:
gui.fill(type=0)
gui.draw_label(text=str('Sound:'), row=1, color=0xffffff, wrap=False)
gui.draw_label(text="%d" % (sound.read()), row=2, color=0xffffff, wrap=False)
gui.update()
Before use, import the mpython module
from mpython import *
We use sound.read() to get the microphone data.
sound.read()
Note
The microphone uses the read() function to read data. The returned value is 12-bit ADC sample data, i.e. the maximum value is 4095 in decimal.
Now that you have learned how to collect ambient sound data, you can combine it with other features to create more interesting scenarios.