mbed Sensor node for Instrumented Booth over ETH.
Dependencies: EthernetInterface-1 MaxbotixDriver Presence HTU21D_TEMP_HUMID_SENSOR_SAMPLE Resources SHARPIR mbed-rtos mbed-src WDT_K64F nsdl_lib
Fork of Trenton_Switch_LPC1768_ETH by
MAX9814/MAX9814.cpp@46:807e9cf63f4c, 2015-07-16 (annotated)
- Committer:
- andcor02
- Date:
- Thu Jul 16 13:28:49 2015 +0000
- Revision:
- 46:807e9cf63f4c
- Parent:
- 25:cb16c5248769
Added Serial VCOM debug over USB.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 25:cb16c5248769 | 1 | /* |
andcor02 | 25:cb16c5248769 | 2 | MAX9814.cpp - MAX9814 sensor library |
andcor02 | 25:cb16c5248769 | 3 | Developed by Andrea Corrado |
andcor02 | 25:cb16c5248769 | 4 | */ |
andcor02 | 25:cb16c5248769 | 5 | |
andcor02 | 25:cb16c5248769 | 6 | #include "mbed.h" |
andcor02 | 25:cb16c5248769 | 7 | #include "MAX9814.h" |
andcor02 | 25:cb16c5248769 | 8 | |
andcor02 | 25:cb16c5248769 | 9 | MAX9814::MAX9814(PinName pin): _pin(pin) { //, _led1(LED1), _led2(LED2), _led3(LED3) { |
andcor02 | 25:cb16c5248769 | 10 | |
andcor02 | 25:cb16c5248769 | 11 | } |
andcor02 | 25:cb16c5248769 | 12 | |
andcor02 | 25:cb16c5248769 | 13 | |
andcor02 | 25:cb16c5248769 | 14 | |
andcor02 | 25:cb16c5248769 | 15 | float MAX9814::sound_level() { |
andcor02 | 25:cb16c5248769 | 16 | |
andcor02 | 25:cb16c5248769 | 17 | _t.start(); |
andcor02 | 25:cb16c5248769 | 18 | float peakToPeak=0, signalMax=0, signalMin=1024; |
andcor02 | 25:cb16c5248769 | 19 | |
andcor02 | 25:cb16c5248769 | 20 | while (_t.read_ms()<50) { |
andcor02 | 25:cb16c5248769 | 21 | _sample=_pin.read(); |
andcor02 | 25:cb16c5248769 | 22 | |
andcor02 | 25:cb16c5248769 | 23 | if (_sample<1024) { |
andcor02 | 25:cb16c5248769 | 24 | if (_sample>signalMax) |
andcor02 | 25:cb16c5248769 | 25 | signalMax=_sample; |
andcor02 | 25:cb16c5248769 | 26 | |
andcor02 | 25:cb16c5248769 | 27 | else if (_sample<signalMin) |
andcor02 | 25:cb16c5248769 | 28 | signalMin=_sample; |
andcor02 | 25:cb16c5248769 | 29 | } |
andcor02 | 25:cb16c5248769 | 30 | } |
andcor02 | 25:cb16c5248769 | 31 | _t.stop(); |
andcor02 | 25:cb16c5248769 | 32 | _t.reset(); |
andcor02 | 25:cb16c5248769 | 33 | peakToPeak=signalMax-signalMin; |
andcor02 | 25:cb16c5248769 | 34 | _value= (peakToPeak*3.3); |
andcor02 | 25:cb16c5248769 | 35 | _value = floor(_value * 100) / 100; |
andcor02 | 25:cb16c5248769 | 36 | |
andcor02 | 25:cb16c5248769 | 37 | return _value; |
andcor02 | 25:cb16c5248769 | 38 | } |