The gator:microphone, which includes a microphone along with an analog-to-I2C converter can be purchased here. The gator:microphone can be used to look at the envelope, or volume of sound, along with a simple gate value, which will tell whether a sound is detected above a certain threshold.
To use this package, go to https://makecode.microbit.org, click Add package
and search for gator-microphone. The package is located here
//Reads the volume of sound
gatorMicrophone.readEnvelopeData()
Use ||Get sound intensity||
to get the value from the envelope channel.
//Reads whether or not sound is above a certain level
gatorMicrophone.readGateData()
Use ||Check for sound||
to return a boolean for whether or not the sound is above a certain level
//Read volume value and write it to the micro:bit screen as a bar graph.
basic.forever(function () {
led.plotBarGraph(
gatorMicrophone.readEnvelopeData(),
2047
)
})
- for PXT/microbit
MIT
gatorMicrophone=github:sparkfun/pxt-gator-microphone