![](/media/cache/group/ep.webp.50x50_q85.jpg)
Mikrophone Sensor
Dependencies: mbed
Mikrophone Sensor für Geräuscherkennung
Tip: zum Testen Finger auf Mikrophone halten und Abfrage umkehren.
Anwendungen
- Klatschschalter z.B. zum Einschalten des Lichtes
- Überwachung Hund (Bellen)
Revision 2:f6a133deaa02, committed 2015-10-15
- Comitter:
- marcel1691
- Date:
- Thu Oct 15 16:20:09 2015 +0000
- Parent:
- 0:f5b93072ca28
- Commit message:
- Neu implementiert mit Zeitfenster
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Apr 17 18:57:20 2015 +0000 +++ b/main.cpp Thu Oct 15 16:20:09 2015 +0000 @@ -4,19 +4,31 @@ // Mikrophone AnalogIn mikrophone( A3 ); -// Poti regelt den Schwellenwert -AnalogIn schwellenwert( A0 ); +// Zeitfenster wo Mikrophone ausgewertert wird +int sampleWindow = 1; +DigitalOut led( D10 ); int main() { while(1) { - float m = mikrophone.read(); - float s = schwellenwert.read(); + // Initialisierung: clock() liefert Zeit seit Einschalten oder Reset des Boards + int startSec = clock() / CLOCKS_PER_SEC; + float max = 0.0f; - if ( m > s ) - printf( "Schwellenwert erreicht %f > %f\n", m, s ); - - wait( 0.2 ); + // Zeitfenster um groessten Wert zu finden + while ( (clock() / CLOCKS_PER_SEC) - startSec < sampleWindow ) + { + float m = mikrophone.read(); + if ( m > max ) + max = m; + } + + // Auswertung + printf( "Maximaler Wert %f\n", max ); + if ( max > 0.4f ) + led = 1; + else + led = 0; } } \ No newline at end of file
--- a/mbed.bld Fri Apr 17 18:57:20 2015 +0000 +++ b/mbed.bld Thu Oct 15 16:20:09 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7 \ No newline at end of file