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.
Fork of SPW2430_Microphone_Hello_World by
main.cpp@1:fd1d5006df70, 2018-10-09 (annotated)
- Committer:
- abraha2d
- Date:
- Tue Oct 09 00:51:23 2018 +0000
- Revision:
- 1:fd1d5006df70
- Parent:
- 0:1a0cc42c459d
Save point
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| 4180_1 | 0:1a0cc42c459d | 1 | #include "mbed.h" |
| 4180_1 | 0:1a0cc42c459d | 2 | //Adafruit MEMs SPW2430 microphone demo - LEDs display audio level |
| 4180_1 | 0:1a0cc42c459d | 3 | BusOut myleds(LED1,LED2,LED3,LED4); |
| 4180_1 | 0:1a0cc42c459d | 4 | |
| 4180_1 | 0:1a0cc42c459d | 5 | class microphone |
| 4180_1 | 0:1a0cc42c459d | 6 | { |
| 4180_1 | 0:1a0cc42c459d | 7 | public : |
| 4180_1 | 0:1a0cc42c459d | 8 | microphone(PinName pin); |
| 4180_1 | 0:1a0cc42c459d | 9 | float read(); |
| 4180_1 | 0:1a0cc42c459d | 10 | operator float (); |
| 4180_1 | 0:1a0cc42c459d | 11 | private : |
| 4180_1 | 0:1a0cc42c459d | 12 | AnalogIn _pin; |
| 4180_1 | 0:1a0cc42c459d | 13 | }; |
| 4180_1 | 0:1a0cc42c459d | 14 | microphone::microphone (PinName pin): |
| 4180_1 | 0:1a0cc42c459d | 15 | _pin(pin) |
| 4180_1 | 0:1a0cc42c459d | 16 | { |
| 4180_1 | 0:1a0cc42c459d | 17 | } |
| 4180_1 | 0:1a0cc42c459d | 18 | float microphone::read() |
| 4180_1 | 0:1a0cc42c459d | 19 | { |
| 4180_1 | 0:1a0cc42c459d | 20 | return _pin.read(); |
| 4180_1 | 0:1a0cc42c459d | 21 | } |
| 4180_1 | 0:1a0cc42c459d | 22 | inline microphone::operator float () |
| 4180_1 | 0:1a0cc42c459d | 23 | { |
| 4180_1 | 0:1a0cc42c459d | 24 | return _pin.read(); |
| 4180_1 | 0:1a0cc42c459d | 25 | } |
| 4180_1 | 0:1a0cc42c459d | 26 | |
| 4180_1 | 0:1a0cc42c459d | 27 | microphone mymicrophone(p16); |
| 4180_1 | 0:1a0cc42c459d | 28 | |
| 4180_1 | 0:1a0cc42c459d | 29 | int main() |
| 4180_1 | 0:1a0cc42c459d | 30 | { |
| 4180_1 | 0:1a0cc42c459d | 31 | while(1) { |
| 4180_1 | 0:1a0cc42c459d | 32 | //read in, subtract 0.67 DC bias, take absolute value, and scale up .1Vpp to 15 for builtin LED display |
| 4180_1 | 0:1a0cc42c459d | 33 | myleds = int(abs((mymicrophone - (0.67/3.3)))*500.0); |
| 4180_1 | 0:1a0cc42c459d | 34 | //Use an 8kHz audio sample rate (phone quality audio); |
| 4180_1 | 0:1a0cc42c459d | 35 | wait(1.0/8000.0); |
| 4180_1 | 0:1a0cc42c459d | 36 | } |
| 4180_1 | 0:1a0cc42c459d | 37 | } |
