Biblioteka za buzzer
Revision 0:49754bfa1d97, committed 2021-12-01
- Comitter:
- petarcicvaric
- Date:
- Wed Dec 01 07:21:02 2021 +0000
- Commit message:
- Biblioteka buzzera
Changed in this revision
buzzer.cpp | Show annotated file Show diff for this revision Revisions of this file |
buzzer.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 49754bfa1d97 buzzer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buzzer.cpp Wed Dec 01 07:21:02 2021 +0000 @@ -0,0 +1,23 @@ +#include "buzzer.h" +#include "mbed.h" + +using namespace mbed; + +Beep::Beep(PinName pin) : _pwm(pin) +{ + _pwm.write(0.0); +} + +void Beep::nobeep() +{ + _pwm.write(0.0); +} +// Frekvencija u Hz i tranjanje tona u sekundama za jedan zvučni signal + +void Beep::beep(float freq, float time) +{ + + _pwm.period(1.0/freq); + _pwm.write(0.5); + toff.attach(this,&Beep::nobeep, time); +} \ No newline at end of file
diff -r 000000000000 -r 49754bfa1d97 buzzer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buzzer.h Wed Dec 01 07:21:02 2021 +0000 @@ -0,0 +1,24 @@ +#ifndef MBED_BEEP_H +#define MBED_BEEP_H + +#include "mbed.h" + +namespace mbed { +//Klasa koja daje funkcije za mjenjanje frekvencije i vremena trajanja tona +class Beep { + +public: + + Beep (PinName pin); + + void beep (float frequency, float time); + + void nobeep(); + +private : + PwmOut _pwm; + Timeout toff; +}; + +} +#endif \ No newline at end of file