Make noise with a piezo buzzer. Use a pwm pin.
Dependents: GliderFuncTest1 DropTest
Fork of beep by
Revision 5:302fee3845f7, committed 2017-04-25
- Comitter:
- chasefarmer2808
- Date:
- Tue Apr 25 17:18:54 2017 +0000
- Parent:
- 4:d8e14429a95f
- Commit message:
- buzzer
Changed in this revision
beep.cpp | Show annotated file Show diff for this revision Revisions of this file |
beep.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r d8e14429a95f -r 302fee3845f7 beep.cpp --- a/beep.cpp Tue Sep 11 08:21:45 2012 +0000 +++ b/beep.cpp Tue Apr 25 17:18:54 2017 +0000 @@ -44,11 +44,14 @@ * @param time - the duration of the tone in seconds */ -void Beep::beep(float freq, float time) { +void Beep::beep(float freq, float time, bool infinate) { _pwm.period(1.0/freq); _pwm.write(0.5); // 50% duty cycle - beep on - toff.attach(this,&Beep::nobeep, time); // time to off + + if (!infinate) { + toff.attach(this,&Beep::nobeep, time); // time to off + } }
diff -r d8e14429a95f -r 302fee3845f7 beep.h --- a/beep.h Tue Sep 11 08:21:45 2012 +0000 +++ b/beep.h Tue Apr 25 17:18:54 2017 +0000 @@ -43,7 +43,7 @@ * @param frequency - the frequency of the tone in Hz * @param time - the duration of the tone in seconds */ - void beep (float frequency, float time); + void beep (float frequency, float time, bool infinate); /** stop the beep instantaneous * usually not used