Toggle the LED of the LPC1768 using an electret microphone

Dependencies:   mbed

sound_switch.cpp

Committer:
faif
Date:
2017-06-04
Revision:
0:01301c8c38ab

File content as of revision 0:01301c8c38ab:

#include "mbed.h"
#include "sound_switch.h"

static const float THRESHOLD = 0.5;
const float BOUNCE_DELAY = 0.2;

enum 
{
    OFF = 0,
    ON = 1
};

int main() 
{
    float i;
    while (true)
    {        
        i = mic;
        if (i < THRESHOLD)
        {
            toggle_state(myled);
            wait(BOUNCE_DELAY);
        }
    }
}

void toggle_state(DigitalOut& s)
{
    switch(s)
    {
        case OFF:
            s = ON;
            break;
        case ON:
            s = OFF;
            break;
    }
}