Microphone

The mPython Board has an onboard microphone that can be used to detect changes in ambient sound.

Example: Display 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 microphone data.

sound.read()

Note

The microphone uses the read() function to read data. The returned value is 12-bit ADC sampling data, with a maximum value of 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.