Sakis Kasampalis
/
sound-switch
Toggle the LED of the LPC1768 using an electret microphone
Revision 0:01301c8c38ab, committed 2017-06-04
- Comitter:
- faif
- Date:
- Sun Jun 04 11:50:37 2017 +0000
- Commit message:
- Toggle the LED of lpc1768 using an electret microphone
Changed in this revision
diff -r 000000000000 -r 01301c8c38ab mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jun 04 11:50:37 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90 \ No newline at end of file
diff -r 000000000000 -r 01301c8c38ab sound_switch.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sound_switch.cpp Sun Jun 04 11:50:37 2017 +0000 @@ -0,0 +1,38 @@ +#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; + } +} \ No newline at end of file
diff -r 000000000000 -r 01301c8c38ab sound_switch.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sound_switch.h Sun Jun 04 11:50:37 2017 +0000 @@ -0,0 +1,9 @@ +#ifndef SOUND_SWITCH_H +#define SOUND_SWITCH_H + +AnalogIn mic(p20); +DigitalOut myled(LED4); + +void toggle_state(DigitalOut& state); + +#endif \ No newline at end of file