Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:826c6171fc1b 1 #ifndef MBED_BEEP_H
shimniok 0:826c6171fc1b 2 #define MBED_BEEP_H
shimniok 0:826c6171fc1b 3
shimniok 0:826c6171fc1b 4 #include "mbed.h"
shimniok 0:826c6171fc1b 5
shimniok 0:826c6171fc1b 6 /** Generates a tone with a buzzer, based on a PwmOut
shimniok 0:826c6171fc1b 7 * The class use a timeout to switch off the sound - it is not blocking while making noise
shimniok 0:826c6171fc1b 8 *
shimniok 0:826c6171fc1b 9 * Example:
shimniok 0:826c6171fc1b 10 * @code
shimniok 0:826c6171fc1b 11 * // Beep at 2kHz for 0.5 seconds
shimniok 0:826c6171fc1b 12 * #include "mbed.h"
shimniok 0:826c6171fc1b 13 * #include "Beep.h"
shimniok 0:826c6171fc1b 14 *
shimniok 0:826c6171fc1b 15 * Beep buzzer(p21);
shimniok 0:826c6171fc1b 16 *
shimniok 0:826c6171fc1b 17 * int main() {
shimniok 0:826c6171fc1b 18 * ...
shimniok 0:826c6171fc1b 19 * buzzer.beep(2000,0.5);
shimniok 0:826c6171fc1b 20 * ...
shimniok 0:826c6171fc1b 21 * }
shimniok 0:826c6171fc1b 22 * @endcode
shimniok 0:826c6171fc1b 23 */
shimniok 0:826c6171fc1b 24 class Beep {
shimniok 0:826c6171fc1b 25
shimniok 0:826c6171fc1b 26 public:
shimniok 0:826c6171fc1b 27
shimniok 0:826c6171fc1b 28 /** Create a Beep object connected to the specified PwmOut pin
shimniok 0:826c6171fc1b 29 *
shimniok 0:826c6171fc1b 30 * @param pin PwmOut pin to connect to
shimniok 0:826c6171fc1b 31 */
shimniok 0:826c6171fc1b 32 Beep(PinName pin);
shimniok 0:826c6171fc1b 33
shimniok 0:826c6171fc1b 34 /** Beep with given frequency and duration.
shimniok 0:826c6171fc1b 35 *
shimniok 0:826c6171fc1b 36 * @param frequency - the frequency of the tone in Hz
shimniok 0:826c6171fc1b 37 * @param time - the duration of the tone in seconds
shimniok 0:826c6171fc1b 38 */
shimniok 0:826c6171fc1b 39 void beep(float frequency, float time);
shimniok 0:826c6171fc1b 40
shimniok 0:826c6171fc1b 41 /** stop the beep instantaneously. Not typically needed, but here just in case
shimniok 0:826c6171fc1b 42 */
shimniok 0:826c6171fc1b 43 void nobeep();
shimniok 0:826c6171fc1b 44
shimniok 0:826c6171fc1b 45 private :
shimniok 0:826c6171fc1b 46 PwmOut _pwm;
shimniok 0:826c6171fc1b 47 Timeout toff;
shimniok 0:826c6171fc1b 48 };
shimniok 0:826c6171fc1b 49 #endif