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.
beep.h@0:ee32d3554f6f, 2015-05-10 (annotated)
- Committer:
- xuszdd
- Date:
- Sun May 10 20:47:53 2015 +0000
- Revision:
- 0:ee32d3554f6f
temperature and pressure
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| xuszdd | 0:ee32d3554f6f | 1 | #ifndef MBED_BEEP_H |
| xuszdd | 0:ee32d3554f6f | 2 | #define MBED_BEEP_H |
| xuszdd | 0:ee32d3554f6f | 3 | |
| xuszdd | 0:ee32d3554f6f | 4 | #include "mbed.h" |
| xuszdd | 0:ee32d3554f6f | 5 | |
| xuszdd | 0:ee32d3554f6f | 6 | |
| xuszdd | 0:ee32d3554f6f | 7 | /** class to make sound with a buzzer, based on a PwmOut |
| xuszdd | 0:ee32d3554f6f | 8 | * The class use a timeout to switch off the sound - it is not blocking while making noise |
| xuszdd | 0:ee32d3554f6f | 9 | * |
| xuszdd | 0:ee32d3554f6f | 10 | * Example: |
| xuszdd | 0:ee32d3554f6f | 11 | * @code |
| xuszdd | 0:ee32d3554f6f | 12 | * // Beep with 1Khz for 0.5 seconds |
| xuszdd | 0:ee32d3554f6f | 13 | * #include "mbed.h" |
| xuszdd | 0:ee32d3554f6f | 14 | * #include "beep.h" |
| xuszdd | 0:ee32d3554f6f | 15 | * |
| xuszdd | 0:ee32d3554f6f | 16 | * Beep buzzer(p21); |
| xuszdd | 0:ee32d3554f6f | 17 | * |
| xuszdd | 0:ee32d3554f6f | 18 | * int main() { |
| xuszdd | 0:ee32d3554f6f | 19 | * ... |
| xuszdd | 0:ee32d3554f6f | 20 | * buzzer.beep(1000,0.5); |
| xuszdd | 0:ee32d3554f6f | 21 | * ... |
| xuszdd | 0:ee32d3554f6f | 22 | * } |
| xuszdd | 0:ee32d3554f6f | 23 | * @endcode |
| xuszdd | 0:ee32d3554f6f | 24 | */ |
| xuszdd | 0:ee32d3554f6f | 25 | |
| xuszdd | 0:ee32d3554f6f | 26 | |
| xuszdd | 0:ee32d3554f6f | 27 | |
| xuszdd | 0:ee32d3554f6f | 28 | namespace mbed { |
| xuszdd | 0:ee32d3554f6f | 29 | |
| xuszdd | 0:ee32d3554f6f | 30 | /* Class: Beep |
| xuszdd | 0:ee32d3554f6f | 31 | * A class witch uses pwm to controle a beeper to generate sounds. |
| xuszdd | 0:ee32d3554f6f | 32 | */ |
| xuszdd | 0:ee32d3554f6f | 33 | class Beep { |
| xuszdd | 0:ee32d3554f6f | 34 | |
| xuszdd | 0:ee32d3554f6f | 35 | |
| xuszdd | 0:ee32d3554f6f | 36 | |
| xuszdd | 0:ee32d3554f6f | 37 | public: |
| xuszdd | 0:ee32d3554f6f | 38 | |
| xuszdd | 0:ee32d3554f6f | 39 | |
| xuszdd | 0:ee32d3554f6f | 40 | /** Create a Beep object connected to the specified PwmOut pin |
| xuszdd | 0:ee32d3554f6f | 41 | * |
| xuszdd | 0:ee32d3554f6f | 42 | * @param pin PwmOut pin to connect to |
| xuszdd | 0:ee32d3554f6f | 43 | */ |
| xuszdd | 0:ee32d3554f6f | 44 | Beep (PinName pin); |
| xuszdd | 0:ee32d3554f6f | 45 | |
| xuszdd | 0:ee32d3554f6f | 46 | /** Beep with given frequency and duration. |
| xuszdd | 0:ee32d3554f6f | 47 | * |
| xuszdd | 0:ee32d3554f6f | 48 | * @param frequency - the frequency of the tone in Hz |
| xuszdd | 0:ee32d3554f6f | 49 | * @param time - the duration of the tone in seconds |
| xuszdd | 0:ee32d3554f6f | 50 | */ |
| xuszdd | 0:ee32d3554f6f | 51 | |
| xuszdd | 0:ee32d3554f6f | 52 | |
| xuszdd | 0:ee32d3554f6f | 53 | void beep (float frequency, float time); |
| xuszdd | 0:ee32d3554f6f | 54 | |
| xuszdd | 0:ee32d3554f6f | 55 | |
| xuszdd | 0:ee32d3554f6f | 56 | |
| xuszdd | 0:ee32d3554f6f | 57 | /** stop the beep instantaneous |
| xuszdd | 0:ee32d3554f6f | 58 | * usually not used |
| xuszdd | 0:ee32d3554f6f | 59 | */ |
| xuszdd | 0:ee32d3554f6f | 60 | |
| xuszdd | 0:ee32d3554f6f | 61 | |
| xuszdd | 0:ee32d3554f6f | 62 | |
| xuszdd | 0:ee32d3554f6f | 63 | void nobeep(); |
| xuszdd | 0:ee32d3554f6f | 64 | |
| xuszdd | 0:ee32d3554f6f | 65 | |
| xuszdd | 0:ee32d3554f6f | 66 | |
| xuszdd | 0:ee32d3554f6f | 67 | |
| xuszdd | 0:ee32d3554f6f | 68 | private : |
| xuszdd | 0:ee32d3554f6f | 69 | PwmOut _pwm; |
| xuszdd | 0:ee32d3554f6f | 70 | Timeout toff; |
| xuszdd | 0:ee32d3554f6f | 71 | }; |
| xuszdd | 0:ee32d3554f6f | 72 | |
| xuszdd | 0:ee32d3554f6f | 73 | |
| xuszdd | 0:ee32d3554f6f | 74 | |
| xuszdd | 0:ee32d3554f6f | 75 | } |
| xuszdd | 0:ee32d3554f6f | 76 | |
| xuszdd | 0:ee32d3554f6f | 77 | |
| xuszdd | 0:ee32d3554f6f | 78 | #endif |