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