Fork of beep lib. Enables play of continous tones and changing of frequency on the fly
Fork of beep by
beep.h@1:ddccf0a4a414, 2011-02-01 (annotated)
- Committer:
- dreschpe
- Date:
- Tue Feb 01 19:08:44 2011 +0000
- Revision:
- 1:ddccf0a4a414
- Parent:
- 0:18e4a9c978ec
- Child:
- 3:5a8242af60ba
0.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:18e4a9c978ec | 1 | #ifndef MBED_BEEP_H |
dreschpe | 0:18e4a9c978ec | 2 | #define MBED_BEEP_H |
dreschpe | 0:18e4a9c978ec | 3 | |
dreschpe | 0:18e4a9c978ec | 4 | #include "mbed.h" |
dreschpe | 0:18e4a9c978ec | 5 | |
dreschpe | 1:ddccf0a4a414 | 6 | /** class to make sound with a buzzer, based on a PwmOut |
dreschpe | 1:ddccf0a4a414 | 7 | * The class use a timeout to switch off the sound - it is not blocking while making noise |
dreschpe | 1:ddccf0a4a414 | 8 | * |
dreschpe | 1:ddccf0a4a414 | 9 | * Example: |
dreschpe | 1:ddccf0a4a414 | 10 | * @code |
dreschpe | 1:ddccf0a4a414 | 11 | * // Beep with 1Khz for 0.5 seconds |
dreschpe | 1:ddccf0a4a414 | 12 | * #include "mbed.h" |
dreschpe | 1:ddccf0a4a414 | 13 | * #include "beep.h" |
dreschpe | 1:ddccf0a4a414 | 14 | * |
dreschpe | 1:ddccf0a4a414 | 15 | * Beep buzzer(p21); |
dreschpe | 1:ddccf0a4a414 | 16 | * |
dreschpe | 1:ddccf0a4a414 | 17 | * int main() { |
dreschpe | 1:ddccf0a4a414 | 18 | * ... |
dreschpe | 1:ddccf0a4a414 | 19 | * buzzer.beep(1000,0.5); |
dreschpe | 1:ddccf0a4a414 | 20 | * ... |
dreschpe | 1:ddccf0a4a414 | 21 | * } |
dreschpe | 1:ddccf0a4a414 | 22 | * @endcode |
dreschpe | 1:ddccf0a4a414 | 23 | */ |
dreschpe | 1:ddccf0a4a414 | 24 | |
dreschpe | 1:ddccf0a4a414 | 25 | |
dreschpe | 0:18e4a9c978ec | 26 | namespace mbed { |
dreschpe | 0:18e4a9c978ec | 27 | |
dreschpe | 0:18e4a9c978ec | 28 | /* Class: Beep |
dreschpe | 0:18e4a9c978ec | 29 | * A class witch uses pwm to controle a beeper to generate sounds. |
dreschpe | 0:18e4a9c978ec | 30 | */ |
dreschpe | 0:18e4a9c978ec | 31 | class Beep { |
dreschpe | 0:18e4a9c978ec | 32 | |
dreschpe | 0:18e4a9c978ec | 33 | public: |
dreschpe | 0:18e4a9c978ec | 34 | |
dreschpe | 1:ddccf0a4a414 | 35 | /** Create a Beep object connected to the specified PwmOut pin |
dreschpe | 1:ddccf0a4a414 | 36 | * |
dreschpe | 1:ddccf0a4a414 | 37 | * @param pin PwmOut pin to connect to |
dreschpe | 1:ddccf0a4a414 | 38 | */ |
dreschpe | 0:18e4a9c978ec | 39 | Beep (PinName pin); |
dreschpe | 0:18e4a9c978ec | 40 | |
dreschpe | 1:ddccf0a4a414 | 41 | /** Beep with given frequency and duration. |
dreschpe | 0:18e4a9c978ec | 42 | * |
dreschpe | 1:ddccf0a4a414 | 43 | * @param frequency - the frequency of the tone in Hz |
dreschpe | 1:ddccf0a4a414 | 44 | * @param time - the duration of the tone in seconds |
dreschpe | 0:18e4a9c978ec | 45 | */ |
dreschpe | 0:18e4a9c978ec | 46 | void beep (float frequency, float time); |
dreschpe | 0:18e4a9c978ec | 47 | |
dreschpe | 1:ddccf0a4a414 | 48 | /** stop the beep instantaneous |
dreschpe | 1:ddccf0a4a414 | 49 | * usually not used |
dreschpe | 1:ddccf0a4a414 | 50 | */ |
dreschpe | 0:18e4a9c978ec | 51 | void nobeep(); |
dreschpe | 0:18e4a9c978ec | 52 | |
dreschpe | 0:18e4a9c978ec | 53 | private : |
dreschpe | 0:18e4a9c978ec | 54 | PwmOut _pwm; |
dreschpe | 0:18e4a9c978ec | 55 | Timeout toff; |
dreschpe | 0:18e4a9c978ec | 56 | }; |
dreschpe | 0:18e4a9c978ec | 57 | |
dreschpe | 0:18e4a9c978ec | 58 | } |
dreschpe | 0:18e4a9c978ec | 59 | #endif |