buzzer
Fork of buzzer by
buzzer.h@2:9133a863f1dd, 2018-03-27 (annotated)
- Committer:
- basvuyk
- Date:
- Tue Mar 27 14:12:18 2018 +0000
- Revision:
- 2:9133a863f1dd
- Parent:
- 1:622b1d533a1c
master V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Reniboy | 0:01eac446ef9f | 1 | #ifndef MBED_BEEP_H |
Reniboy | 0:01eac446ef9f | 2 | #define MBED_BEEP_H |
Reniboy | 0:01eac446ef9f | 3 | |
Reniboy | 0:01eac446ef9f | 4 | #include "mbed.h" |
Reniboy | 1:622b1d533a1c | 5 | /** |
Reniboy | 1:622b1d533a1c | 6 | @namespace Beep Library |
Reniboy | 1:622b1d533a1c | 7 | @brief Contains member functions for the speaker funtion that allow for sending of frequency of sounds and duration through pwm |
Reniboy | 1:622b1d533a1c | 8 | @Author Peter Drescher (I do not own the rights to this library and it has been rightly attributed to its owner |
Reniboy | 1:622b1d533a1c | 9 | @Revision 2012 |
Reniboy | 1:622b1d533a1c | 10 | |
Reniboy | 1:622b1d533a1c | 11 | **/ |
Reniboy | 1:622b1d533a1c | 12 | |
Reniboy | 1:622b1d533a1c | 13 | |
Reniboy | 0:01eac446ef9f | 14 | |
Reniboy | 0:01eac446ef9f | 15 | /** class to make sound with a buzzer, roughly based on a library created by Peter Drescher |
Reniboy | 0:01eac446ef9f | 16 | * The class use a timeout to switch off the sound - it is not blocking while making noise |
Reniboy | 0:01eac446ef9f | 17 | * |
Reniboy | 0:01eac446ef9f | 18 | * Example: |
Reniboy | 0:01eac446ef9f | 19 | * @code |
Reniboy | 0:01eac446ef9f | 20 | * // Beep with 1Khz for 0.5 seconds |
Reniboy | 0:01eac446ef9f | 21 | * #include "mbed.h" |
Reniboy | 0:01eac446ef9f | 22 | * #include "buzzer.h" |
Reniboy | 0:01eac446ef9f | 23 | * |
Reniboy | 0:01eac446ef9f | 24 | * Beep buzzer(PTC2); |
Reniboy | 0:01eac446ef9f | 25 | * |
Reniboy | 0:01eac446ef9f | 26 | * int main() { |
Reniboy | 0:01eac446ef9f | 27 | * ... |
Reniboy | 0:01eac446ef9f | 28 | * buzzer.beep(1000,0.5); |
Reniboy | 0:01eac446ef9f | 29 | * ... |
Reniboy | 0:01eac446ef9f | 30 | * } |
Reniboy | 0:01eac446ef9f | 31 | * @endcode |
Reniboy | 0:01eac446ef9f | 32 | */ |
Reniboy | 0:01eac446ef9f | 33 | |
Reniboy | 0:01eac446ef9f | 34 | |
Reniboy | 0:01eac446ef9f | 35 | namespace mbed { |
Reniboy | 0:01eac446ef9f | 36 | |
Reniboy | 0:01eac446ef9f | 37 | /* Class: Beep |
Reniboy | 0:01eac446ef9f | 38 | * A class witch uses pwm to controle a beeper to generate sounds. |
Reniboy | 0:01eac446ef9f | 39 | */ |
Reniboy | 0:01eac446ef9f | 40 | class Beep { |
Reniboy | 0:01eac446ef9f | 41 | |
Reniboy | 0:01eac446ef9f | 42 | public: |
Reniboy | 0:01eac446ef9f | 43 | |
Reniboy | 0:01eac446ef9f | 44 | /** Create a Beep object connected to the specified PwmOut pin |
Reniboy | 0:01eac446ef9f | 45 | * |
Reniboy | 0:01eac446ef9f | 46 | * @param pin PwmOut pin to connect to |
Reniboy | 0:01eac446ef9f | 47 | */ |
Reniboy | 0:01eac446ef9f | 48 | Beep (PinName pin); |
Reniboy | 0:01eac446ef9f | 49 | |
Reniboy | 0:01eac446ef9f | 50 | /** Beep with given frequency and duration. |
Reniboy | 0:01eac446ef9f | 51 | * |
Reniboy | 0:01eac446ef9f | 52 | * @param frequency - the frequency of the tone in Hz |
Reniboy | 0:01eac446ef9f | 53 | * @param time - the duration of the tone in seconds |
Reniboy | 0:01eac446ef9f | 54 | */ |
Reniboy | 0:01eac446ef9f | 55 | void beep (float frequency, float time); |
Reniboy | 0:01eac446ef9f | 56 | |
Reniboy | 0:01eac446ef9f | 57 | /** stop the beep instantaneous |
Reniboy | 0:01eac446ef9f | 58 | * usually not used |
Reniboy | 0:01eac446ef9f | 59 | */ |
Reniboy | 0:01eac446ef9f | 60 | void nobeep(); |
Reniboy | 0:01eac446ef9f | 61 | |
Reniboy | 0:01eac446ef9f | 62 | private : |
Reniboy | 0:01eac446ef9f | 63 | PwmOut _pwm; |
Reniboy | 0:01eac446ef9f | 64 | Timeout toff; |
Reniboy | 0:01eac446ef9f | 65 | }; |
Reniboy | 0:01eac446ef9f | 66 | |
Reniboy | 0:01eac446ef9f | 67 | } |
Reniboy | 0:01eac446ef9f | 68 | #endif |
Reniboy | 0:01eac446ef9f | 69 | |
Reniboy | 0:01eac446ef9f | 70 |