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
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 }
Generated on Tue Jul 12 2022 11:14:19 by
1.7.2