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.
Fork of beep by
beep.c@0:18e4a9c978ec, 2011-02-01 (annotated)
- Committer:
- dreschpe
- Date:
- Tue Feb 01 18:44:45 2011 +0000
- Revision:
- 0:18e4a9c978ec
- Child:
- 2:a34405c20cf5
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dreschpe | 0:18e4a9c978ec | 1 | #include "beep.h" |
| dreschpe | 0:18e4a9c978ec | 2 | #include "mbed.h" |
| dreschpe | 0:18e4a9c978ec | 3 | |
| dreschpe | 0:18e4a9c978ec | 4 | using namespace mbed; |
| dreschpe | 0:18e4a9c978ec | 5 | // constructor |
| dreschpe | 0:18e4a9c978ec | 6 | Beep::Beep(PinName pin) : _pwm(pin) { |
| dreschpe | 0:18e4a9c978ec | 7 | _pwm.write(0.0); // after creating it have to be off |
| dreschpe | 0:18e4a9c978ec | 8 | } |
| dreschpe | 0:18e4a9c978ec | 9 | |
| dreschpe | 0:18e4a9c978ec | 10 | // switch off |
| dreschpe | 0:18e4a9c978ec | 11 | void Beep::nobeep() { |
| dreschpe | 0:18e4a9c978ec | 12 | _pwm.write(0.0); |
| dreschpe | 0:18e4a9c978ec | 13 | } |
| dreschpe | 0:18e4a9c978ec | 14 | |
| dreschpe | 0:18e4a9c978ec | 15 | |
| dreschpe | 0:18e4a9c978ec | 16 | // beep |
| dreschpe | 0:18e4a9c978ec | 17 | void Beep::beep(float freq, float time) { |
| dreschpe | 0:18e4a9c978ec | 18 | |
| dreschpe | 0:18e4a9c978ec | 19 | _pwm.period(1.0/freq); |
| dreschpe | 0:18e4a9c978ec | 20 | _pwm.write(0.5); // 50% duty cycle - beep on |
| dreschpe | 0:18e4a9c978ec | 21 | toff.attach(this,&Beep::nobeep, time); // time to off |
| dreschpe | 0:18e4a9c978ec | 22 | } |
| dreschpe | 0:18e4a9c978ec | 23 | |
| dreschpe | 0:18e4a9c978ec | 24 | |
| dreschpe | 0:18e4a9c978ec | 25 | |
| dreschpe | 0:18e4a9c978ec | 26 |
