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.
Diff: GROVE_SOUND.cpp
- Revision:
- 0:fa75a7cf49b6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GROVE_SOUND.cpp Sun Jul 02 11:33:55 2017 +0000 @@ -0,0 +1,23 @@ +#include "GROVE_SOUND.h" +#include "mbed.h" + +GROVE_SOUND::GROVE_SOUND(PinName pin) : _pin(pin){ + sum = 0; + average = 0; +} + +float GROVE_SOUND::get_decibels(){ + + float values[1000]; + for(int i=0;i<1000;i++){ + values[i] = _pin.read()* 3.3; + wait(0.0001); + } + + for(int j=0;j<1000;j++){ + sum += values[j]; + } + average = sum/1000; + decibels = average * 29; + return decibels; + }