Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
- Committer:
 - 4180_1
 - Date:
 - 2015-11-28
 - Revision:
 - 0:1a0cc42c459d
 
File content as of revision 0:1a0cc42c459d:
#include "mbed.h"
//Adafruit MEMs SPW2430 microphone demo - LEDs display audio level
BusOut myleds(LED1,LED2,LED3,LED4);
class microphone
{
public :
    microphone(PinName pin);
    float read();
    operator float ();
private :
    AnalogIn _pin;
};
microphone::microphone (PinName pin):
    _pin(pin)
{
}
float microphone::read()
{
    return _pin.read();
}
inline microphone::operator float ()
{
    return _pin.read();
}
microphone mymicrophone(p16);
int main()
{
    while(1) {
//read in, subtract 0.67 DC bias, take absolute value, and scale up .1Vpp to 15 for builtin LED display
        myleds = int(abs((mymicrophone - (0.67/3.3)))*500.0);
//Use an 8kHz audio sample rate (phone quality audio);
        wait(1.0/8000.0);
    }
}