Grove soundsensor lib
soundsensor.cpp
- Committer:
- math991e
- Date:
- 2019-01-17
- Revision:
- 1:29daa2bdd0c6
- Parent:
- 0:18d442efc99a
- Child:
- 3:372e67c123c3
File content as of revision 1:29daa2bdd0c6:
#include "soundsensor.h" soundsensor::soundsensor(PinName pin){ soundsensor::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 **/ return 0; } float soundsensor::listen(bool toDb){ AnalogIn sensor(this->getPin()); float value = sensor.read_u16(); if(toDb){ return this->convertToDb(value); }else{ return value; } }