buzzer

Dependents:   GhostBuzzter

Files at this revision

API Documentation at this revision

Comitter:
briceetpapaul
Date:
Sun Dec 22 11:13:24 2019 +0000
Commit message:
fini

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 c5a5dc015c10 Buzzer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Buzzer.cpp	Sun Dec 22 11:13:24 2019 +0000
@@ -0,0 +1,45 @@
+#include "Buzzer.h"
+
+Buzzer::Buzzer(PinName pin)
+{
+    _buzzer = new DigitalOut(pin);
+    //_ticker = new Ticker();
+}
+
+Buzzer::Buzzer(PinName pin, float period)
+{
+    _buzzer = new DigitalOut(pin);
+    _period = period;
+    //_ticker = new Ticker();
+}
+
+Buzzer::~Buzzer()
+{
+    delete _buzzer;
+}
+
+void Buzzer::definirPeriode(float period)
+{
+    _period = period;
+}
+
+void Buzzer::changerPeriode(float period)
+{
+    definirPeriode(period);
+    demarrer();
+}
+
+void Buzzer::demarrer()
+{
+    _ticker.attach(callback(this, &Buzzer::bipper), _period);
+}
+
+void Buzzer::arreter()
+{
+    _ticker.detach();
+}
+
+void Buzzer::bipper()
+{
+    *_buzzer = !*_buzzer;
+}
\ No newline at end of file
diff -r 000000000000 -r c5a5dc015c10 Buzzer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Buzzer.h	Sun Dec 22 11:13:24 2019 +0000
@@ -0,0 +1,25 @@
+#ifndef BUZZER_H
+#define BUZZER_H
+
+#include "mbed.h"
+
+class Buzzer
+{
+    public:
+        Buzzer(PinName pin);
+        Buzzer(PinName pin, float period);
+        ~Buzzer();
+        void definirPeriode(float period);
+        void changerPeriode(float period);
+        void demarrer();
+        void arreter();
+        
+    private:
+        float _period;
+        DigitalOut* _buzzer;
+        Ticker _ticker;
+        
+        void bipper();
+};
+
+#endif // BUZZER_H
\ No newline at end of file