Sakis Kasampalis
/
beep
Send a beep to a speaker
Revision 0:c2090cf6119d, committed 2017-01-22
- Comitter:
- faif
- Date:
- Sun Jan 22 19:14:30 2017 +0000
- Commit message:
- Beep a speaker
Changed in this revision
diff -r 000000000000 -r c2090cf6119d beep.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beep.cpp Sun Jan 22 19:14:30 2017 +0000 @@ -0,0 +1,24 @@ +#include "mbed.h" +#include "beep.h" + +static const float delay = 1E-3; // 0.001 + +int main() +{ + while (true) + { + if (button) + { + play_sound(speaker, delay); + } + } +} + + +void play_sound(DigitalOut& speaker, float delay) +{ + speaker = 1; + wait(delay); + speaker = 0; + wait(delay); +} \ No newline at end of file
diff -r 000000000000 -r c2090cf6119d beep.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beep.h Sun Jan 22 19:14:30 2017 +0000 @@ -0,0 +1,9 @@ +#ifndef BEEP_H +#define BEEP_H + +DigitalOut speaker(p20); +DigitalIn button(p18); + +void play_sound(DigitalOut& out, float delay); + +#endif \ No newline at end of file
diff -r 000000000000 -r c2090cf6119d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jan 22 19:14:30 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5 \ No newline at end of file