Toggle the LED of the LPC1768 using an electret microphone

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sound_switch.cpp Source File

sound_switch.cpp

00001 #include "mbed.h"
00002 #include "sound_switch.h"
00003 
00004 static const float THRESHOLD = 0.5;
00005 const float BOUNCE_DELAY = 0.2;
00006 
00007 enum 
00008 {
00009     OFF = 0,
00010     ON = 1
00011 };
00012 
00013 int main() 
00014 {
00015     float i;
00016     while (true)
00017     {        
00018         i = mic;
00019         if (i < THRESHOLD)
00020         {
00021             toggle_state(myled);
00022             wait(BOUNCE_DELAY);
00023         }
00024     }
00025 }
00026 
00027 void toggle_state(DigitalOut& s)
00028 {
00029     switch(s)
00030     {
00031         case OFF:
00032             s = ON;
00033             break;
00034         case ON:
00035             s = OFF;
00036             break;
00037     }
00038 }