Program to control Electret Microphone Amplifier - MAX9814 from adafruit. Allows: To sample analogue voltage to transform into rough sound level. Transfer sound level to visual indicator, volume bar such as 4 LEDs on LPC11U24.

Dependencies:   MAX9814_Electret_Microphone_LED_Volume_Indicator mbed

Files at this revision

API Documentation at this revision

Comitter:
andcor02
Date:
Sun Nov 02 17:32:24 2014 +0000
Parent:
1:380e6ab41172
Child:
3:0e670b36b3d6
Commit message:
Program to control Electret Microphone Amplifier - MAX9814 from adafruit.; ; Allows:; ; To sample analogue voltage to transform into rough sound level.; ; Transfer sound level to visual indicator, volume bar such as 4 LEDs on LPC11U24.; ;

Changed in this revision

Hammer_MicrophoneSensor.cpp Show diff for this revision Revisions of this file
Hammer_MicrophoneSensor.h Show diff for this revision Revisions of this file
MAX9814.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Hammer_MicrophoneSensor.cpp	Sun Nov 02 17:12:22 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-#include "mbed.h"
-#include "Hammer_MicrophoneSensor.h"
-
-MAX9814::MAX9814(PinName pin): _pin(pin), _led1(LED1), _led2(LED2), _led3(LED3), _led4(LED4) {
-    calibration();
-}
-
-
-void MAX9814::led_array(float x ) {
-
-    if (_value<x+0.05) {
-            _led1=0;
-            _led2=0;
-            _led3=0;
-            _led4=0;
-    }
-    if (_value>x+0.05&&_value<0.5+x) {
-            _led1=1;
-            _led2=0;
-            _led3=0;
-            _led4=0;
-    }
-    if (_value>0.5+x&&_value<1+x) {
-            _led1=1;
-            _led2=1;
-            _led3=0;
-            _led4=0;
-    }
-    if (_value>1+x&&_value<1.2+x) {
-            _led1=1;
-            _led2=1;
-            _led3=1;
-            _led4=0;
-    }
-    if (_value>1.2+x&&_value<2.8+x) {
-            _led1=1;
-            _led2=1;
-            _led3=1;
-            _led4=1;
-    }
-}
-
-float MAX9814::calibration() {
-    
-    _t.start();
-    _t1.start();
-    float peakToPeak=0, signalMax=0, signalMin=1024;
-
-    while (_t1.read()<1) {
-        while (_t.read_ms()<50) {
-            _sample=_pin.read();
-
-            if (_sample<1024) {
-                if (_sample>signalMax)
-                    signalMax=_sample;
-
-                else if (_sample<signalMin)
-                    signalMin=_sample;
-            }
-        }
-     _t.reset();
-     peakToPeak=signalMax-signalMin;
-     _value= (peakToPeak*3.3);
-     _value = floor(_value * 100) / 100;
-     _sum+=_value;
-     _count++;
-    }
-    _average=_sum/_count;
-    _t1.reset();
-
-    return _average;
-}
-
-float MAX9814::sound_level() {
-
-    _t.start();
-    float peakToPeak=0, signalMax=0, signalMin=1024;
-
-    while (_t.read_ms()<50) {
-        _sample=_pin.read();
-
-        if (_sample<1024) {
-            if (_sample>signalMax)
-                signalMax=_sample;
-
-            else if (_sample<signalMin)
-                signalMin=_sample;
-        }
-    }
-    _t.reset();
-    peakToPeak=signalMax-signalMin;
-    _value= (peakToPeak*3.3);
-    _value = floor(_value * 100) / 100;
-    _sum+=_value;
-    _count++;
-
-    return _value;
-}
-
-
-void MAX9814::volume_indicator() {
-        led_array(_average);
-        sound_level();
-}
--- a/Hammer_MicrophoneSensor.h	Sun Nov 02 17:12:22 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#ifndef MBED_MIC_H
-#define MBED_MIC_H
-
-#include "mbed.h"
-
-class MAX9814 {
-    
-public:
-
-    MAX9814(PinName pin);
-    
-    void led_array(float x);
-    
-    void volume_indicator();
-    
-    float calibration();
-    
-    float sound_level();
-
-protected:
-    AnalogIn _pin;
-    BusOut _led1, _led2, _led3, _led4;
-    float _value,_sum,_average;
-    int _count;
-    float _sample;
-    Timer _t,_t1;
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX9814.lib	Sun Nov 02 17:32:24 2014 +0000
@@ -0,0 +1,1 @@
+MAX9814#49d2ee7cb020
--- a/main.cpp	Sun Nov 02 17:12:22 2014 +0000
+++ b/main.cpp	Sun Nov 02 17:32:24 2014 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "Hammer_MicrophoneSensor.h"
+#include "MAX9814.h"
 Serial pc (USBTX, USBRX);