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.
Revision 0:fa75a7cf49b6, committed 2017-07-02
- Comitter:
- ngomez
- Date:
- Sun Jul 02 11:33:55 2017 +0000
- Commit message:
- Library for grove sound sensor
Changed in this revision
GROVE_SOUND.cpp | Show annotated file Show diff for this revision Revisions of this file |
GROVE_SOUND.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r fa75a7cf49b6 GROVE_SOUND.cpp --- /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; + }
diff -r 000000000000 -r fa75a7cf49b6 GROVE_SOUND.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GROVE_SOUND.h Sun Jul 02 11:33:55 2017 +0000 @@ -0,0 +1,29 @@ +/*************************************************** + This is a library for grove sound sensor + + Written by Nerea Gómez. + + ****************************************************/ + +#ifndef MBED_GROVE_SOUND_H +#define MBED_GROVE_SOUND_H +#include "mbed.h" + +class GROVE_SOUND { + public: + + GROVE_SOUND(PinName pin); + float get_decibels(); + + private: + + AnalogIn _pin; + float decibels; + float values[1000]; + float sum; + float average; + +}; + +#endif + \ No newline at end of file