Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
UI/Beep/Beep.cpp@0:826c6171fc1b, 2012-06-20 (annotated)
- Committer:
- shimniok
- Date:
- Wed Jun 20 14:57:48 2012 +0000
- Revision:
- 0:826c6171fc1b
Updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:826c6171fc1b | 1 | #include "mbed.h" |
shimniok | 0:826c6171fc1b | 2 | #include "Beep.h" |
shimniok | 0:826c6171fc1b | 3 | |
shimniok | 0:826c6171fc1b | 4 | /** Create a Beep object connected to the specified PwmOut pin |
shimniok | 0:826c6171fc1b | 5 | * |
shimniok | 0:826c6171fc1b | 6 | * @param pin PwmOut pin to connect to |
shimniok | 0:826c6171fc1b | 7 | */ |
shimniok | 0:826c6171fc1b | 8 | Beep::Beep(PinName pin) : _pwm(pin) { |
shimniok | 0:826c6171fc1b | 9 | _pwm.write(0.0); // after creating it have to be off |
shimniok | 0:826c6171fc1b | 10 | } |
shimniok | 0:826c6171fc1b | 11 | |
shimniok | 0:826c6171fc1b | 12 | /** Stop the beep instantaneously. |
shimniok | 0:826c6171fc1b | 13 | */ |
shimniok | 0:826c6171fc1b | 14 | void Beep::nobeep() { |
shimniok | 0:826c6171fc1b | 15 | _pwm.write(0.0); |
shimniok | 0:826c6171fc1b | 16 | } |
shimniok | 0:826c6171fc1b | 17 | |
shimniok | 0:826c6171fc1b | 18 | /** Beep with given frequency and duration. |
shimniok | 0:826c6171fc1b | 19 | * |
shimniok | 0:826c6171fc1b | 20 | * @param frequency - the frequency of the tone in Hz |
shimniok | 0:826c6171fc1b | 21 | * @param time - the duration of the tone in seconds |
shimniok | 0:826c6171fc1b | 22 | */ |
shimniok | 0:826c6171fc1b | 23 | |
shimniok | 0:826c6171fc1b | 24 | void Beep::beep(float freq, float time) { |
shimniok | 0:826c6171fc1b | 25 | |
shimniok | 0:826c6171fc1b | 26 | _pwm.period(1.0/freq); |
shimniok | 0:826c6171fc1b | 27 | _pwm.write(0.5); // 50% duty cycle - beep on |
shimniok | 0:826c6171fc1b | 28 | toff.attach(this,&Beep::nobeep, time); // time to off |
shimniok | 0:826c6171fc1b | 29 | } |
shimniok | 0:826c6171fc1b | 30 | |
shimniok | 0:826c6171fc1b | 31 | |
shimniok | 0:826c6171fc1b | 32 | |
shimniok | 0:826c6171fc1b | 33 |