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.
Diff: Beeper.cpp
- Revision:
- 1:1b8125937f28
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Beeper.cpp Sun Feb 01 00:43:25 2015 +0000 @@ -0,0 +1,27 @@ +#include "Beeper.h" + +DigitalOut Beeper::_speaker(P0_18); + +void Beeper::beep(int freq, int ms) +{ + float delay = 1.0f / (float)freq; + float duration = (float)ms / 1000.0f; + while (duration > 0) + { + _speaker = !_speaker; + wait(delay); + duration -= delay; + } +} + +void Beeper::noise(int freq, int ms) +{ + float delay = 1.0f / (float)freq; + float duration = (float)ms / 1000.0f; + while (duration > 0) + { + _speaker = lfsr_rand() & 0x01; + wait(delay); + duration -= delay; + } +} \ No newline at end of file