Junwei Zang / Mbed 2 deprecated Embedded_Systems_Project

Dependencies:   mbed

Committer:
el14jz
Date:
Thu May 07 11:26:58 2015 +0000
Revision:
0:411f355688a5
Child:
1:ff57945c704c
Embedded System Project(Arcade Game)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el14jz 0:411f355688a5 1 #ifndef MBED_BEEP_H
el14jz 0:411f355688a5 2 #define MBED_BEEP_H
el14jz 0:411f355688a5 3
el14jz 0:411f355688a5 4 #include "mbed.h"
el14jz 0:411f355688a5 5
el14jz 0:411f355688a5 6 /** class to make sound with a buzzer, based on a PwmOut
el14jz 0:411f355688a5 7 * The class use a timeout to switch off the sound - it is not blocking while making noise
el14jz 0:411f355688a5 8 *
el14jz 0:411f355688a5 9 * Example:
el14jz 0:411f355688a5 10 * @code
el14jz 0:411f355688a5 11 * // Beep with 1Khz for 0.5 seconds
el14jz 0:411f355688a5 12 * #include "mbed.h"
el14jz 0:411f355688a5 13 * #include "beep.h"
el14jz 0:411f355688a5 14 *
el14jz 0:411f355688a5 15 * Beep buzzer(p21);
el14jz 0:411f355688a5 16 *
el14jz 0:411f355688a5 17 * int main() {
el14jz 0:411f355688a5 18 * ...
el14jz 0:411f355688a5 19 * buzzer.beep(1000,0.5);
el14jz 0:411f355688a5 20 * ...
el14jz 0:411f355688a5 21 * }
el14jz 0:411f355688a5 22 * @endcode
el14jz 0:411f355688a5 23 */
el14jz 0:411f355688a5 24
el14jz 0:411f355688a5 25
el14jz 0:411f355688a5 26 namespace mbed {
el14jz 0:411f355688a5 27
el14jz 0:411f355688a5 28 /* Class: Beep
el14jz 0:411f355688a5 29 * A class witch uses pwm to controle a beeper to generate sounds.
el14jz 0:411f355688a5 30 */
el14jz 0:411f355688a5 31 class Beep {
el14jz 0:411f355688a5 32
el14jz 0:411f355688a5 33 public:
el14jz 0:411f355688a5 34
el14jz 0:411f355688a5 35 /** Create a Beep object connected to the specified PwmOut pin
el14jz 0:411f355688a5 36 *
el14jz 0:411f355688a5 37 * @param pin PwmOut pin to connect to
el14jz 0:411f355688a5 38 */
el14jz 0:411f355688a5 39 Beep (PinName pin);
el14jz 0:411f355688a5 40
el14jz 0:411f355688a5 41 /** Beep with given frequency and duration.
el14jz 0:411f355688a5 42 *
el14jz 0:411f355688a5 43 * @param frequency - the frequency of the tone in Hz
el14jz 0:411f355688a5 44 * @param time - the duration of the tone in seconds
el14jz 0:411f355688a5 45 */
el14jz 0:411f355688a5 46 void beep (float frequency, float time);
el14jz 0:411f355688a5 47
el14jz 0:411f355688a5 48 /** stop the beep instantaneous
el14jz 0:411f355688a5 49 * usually not used
el14jz 0:411f355688a5 50 */
el14jz 0:411f355688a5 51 void nobeep();
el14jz 0:411f355688a5 52
el14jz 0:411f355688a5 53 private :
el14jz 0:411f355688a5 54 PwmOut _pwm;
el14jz 0:411f355688a5 55 Timeout toff;
el14jz 0:411f355688a5 56 };
el14jz 0:411f355688a5 57
el14jz 0:411f355688a5 58 }
el14jz 0:411f355688a5 59 #endif