Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P
Diff: Microphone.cpp
- Revision:
- 33:5d86c111d9bc
- Parent:
- 8:0222df74596e
--- a/Microphone.cpp Mon Apr 23 16:05:32 2018 +0000 +++ b/Microphone.cpp Wed Apr 25 15:39:03 2018 +0000 @@ -2,7 +2,7 @@ #define UINT8_MAX 255 Microphone::Microphone (PinName pin): - _pin(pin) + _pin(pin), dc(.67 / 3.3) {} float Microphone::read() @@ -18,5 +18,11 @@ uint8_t Microphone::getData() { // This can be better but this should work for now - return (read() - (0.67/3.3)) * UINT8_MAX; + const static float alpha = 0.99999f; + float sample = (float)read(); + + dc = alpha*dc + (1.0f - alpha)*sample; + + sample = 0.5f + (sample - dc)* 33.0f; + return sample * UINT8_MAX; } \ No newline at end of file