Grove soundsensor lib
Diff: soundsensor.cpp
- Revision:
- 0:18d442efc99a
- Child:
- 1:29daa2bdd0c6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/soundsensor.cpp Thu Jan 17 07:42:19 2019 +0000 @@ -0,0 +1,33 @@ +#include "soundsensor.h" + +soundsensor::soundsensor(PinName pin){ + play_buzzer::setPin(pin); +} + +void soundsensor::setPin(PinName pin){ + this->_pin=pin; +} + +PinName soundsensor::getPin(){ + return this->_pin; +} + +float soundsensor::convertToDb(float value){ + return 16.801 * log (value/65535) + 9.872; +} + +float soundsensor::revertFromDb(float value){ +/** +*CODE NEEDS TO BE IMPLEMENTED +**/ +} + +float soundsensor::listen(bool toDb){ + AnalogIn(this->getPin()) sensor; + float value = sensor.read_u16(); + if(toDb){ + return this->convertToDb(value); + }else{ + return value; + } +} \ No newline at end of file