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

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Beep.cpp Source File

Beep.cpp

00001 #include "mbed.h"
00002 #include "Beep.h"
00003 
00004 /** Create a Beep object connected to the specified PwmOut pin
00005  *
00006  * @param pin PwmOut pin to connect to 
00007  */
00008 Beep::Beep(PinName pin) : _pwm(pin) {
00009     _pwm.write(0.0);     // after creating it have to be off
00010 }
00011 
00012  /** Stop the beep instantaneously.
00013   */
00014 void Beep::nobeep() {
00015     _pwm.write(0.0);
00016 }
00017 
00018 /** Beep with given frequency and duration.
00019  *
00020  * @param frequency - the frequency of the tone in Hz
00021  * @param time - the duration of the tone in seconds
00022  */
00023      
00024 void Beep::beep(float freq, float time) {
00025 
00026     _pwm.period(1.0/freq);
00027     _pwm.write(0.5);            // 50% duty cycle - beep on
00028     toff.attach(this,&Beep::nobeep, time);   // time to off
00029 }
00030 
00031 
00032 
00033