ECE 4180 - Final Project Team / Mbed 2 deprecated WalkieTalkie

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Microphone.cpp Source File

Microphone.cpp

00001 #include  "Microphone.h"
00002 #define UINT8_MAX 255
00003 
00004 Microphone::Microphone (PinName pin):
00005     _pin(pin), dc(.67 / 3.3)
00006 {}
00007 
00008 float Microphone::read()
00009 {
00010     return _pin.read();
00011 }
00012 
00013 inline Microphone::operator float ()
00014 {
00015     return _pin.read();
00016 }
00017 
00018 uint8_t Microphone::getData()
00019 {
00020     // This can be better but this should work for now
00021     const static float alpha = 0.99999f;
00022     float sample = (float)read();
00023     
00024     dc = alpha*dc + (1.0f - alpha)*sample;
00025     
00026     sample = 0.5f + (sample - dc)* 33.0f;
00027     return sample * UINT8_MAX;
00028 }