ECE 4180 - Final Project Team / Mbed 2 deprecated WalkieTalkie

Dependencies:   mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P

Revision:
14:4637a9f02919
Parent:
12:efcfe4c0d9f2
Child:
20:e068469ffb89
--- a/Speaker.cpp	Fri Apr 20 14:38:27 2018 +0000
+++ b/Speaker.cpp	Fri Apr 20 15:15:59 2018 +0000
@@ -1,5 +1,13 @@
-#include "Spearker.h"
+#include "Speaker.h"
+#define UINT8_MAX 255
+
+Speaker::Speaker(PinName pin) : _pin(pin), dc(0.67f / 3.3f) {}
 
-Speaker::Speaker(PinName pin) : _pin(pin) {}
-
-void Speaker::write(uint8_t value) {}
\ No newline at end of file
+void Speaker::write(uint8_t value) {
+    const static float alpha = 0.99999f;
+    float sample = (float)value / UINT8_MAX;
+    
+    dc = alpha*dc + (1.0f - alpha)*sample;
+    
+    _pin = 0.5f + (sample - dc)* 33.0f;
+}
\ No newline at end of file