Nerea Gomez / GROVE_SOUND

Files at this revision

API Documentation at this revision

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