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.
Dependents: MSGEQ7_Hello_World LCD_Spectrum_Analyzer 4180_Lab4 MSGEQ7_Hello_World ... more
MSGEQ7.cpp@0:974a4855a7f8, 2013-10-16 (annotated)
- Committer:
- chrisisthefish
- Date:
- Wed Oct 16 06:33:29 2013 +0000
- Revision:
- 0:974a4855a7f8
Created MSGEQ7 Library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chrisisthefish | 0:974a4855a7f8 | 1 | /* |
| chrisisthefish | 0:974a4855a7f8 | 2 | MSGEQ7 Library for interfacing to the MSGEQ7 Seven Band Grapic Equalizer chip made by Mixed Signal Integration |
| chrisisthefish | 0:974a4855a7f8 | 3 | |
| chrisisthefish | 0:974a4855a7f8 | 4 | Chris Wilson |
| chrisisthefish | 0:974a4855a7f8 | 5 | twilson8@gatech.edu |
| chrisisthefish | 0:974a4855a7f8 | 6 | 10/16/2013 |
| chrisisthefish | 0:974a4855a7f8 | 7 | */ |
| chrisisthefish | 0:974a4855a7f8 | 8 | |
| chrisisthefish | 0:974a4855a7f8 | 9 | #include "MSGEQ7.h" |
| chrisisthefish | 0:974a4855a7f8 | 10 | #include "mbed.h" |
| chrisisthefish | 0:974a4855a7f8 | 11 | |
| chrisisthefish | 0:974a4855a7f8 | 12 | MSGEQ7::MSGEQ7(PinName reset, PinName strobe, PinName analog): |
| chrisisthefish | 0:974a4855a7f8 | 13 | _reset(reset), _strobe(strobe), _analog(analog) { |
| chrisisthefish | 0:974a4855a7f8 | 14 | |
| chrisisthefish | 0:974a4855a7f8 | 15 | // Initial condition of output enables |
| chrisisthefish | 0:974a4855a7f8 | 16 | _reset = 0; |
| chrisisthefish | 0:974a4855a7f8 | 17 | _strobe = 1; |
| chrisisthefish | 0:974a4855a7f8 | 18 | } |
| chrisisthefish | 0:974a4855a7f8 | 19 | |
| chrisisthefish | 0:974a4855a7f8 | 20 | /* The user is given two choices as to what format the data is returned to them in: |
| chrisisthefish | 0:974a4855a7f8 | 21 | 1. One byte - readByte |
| chrisisthefish | 0:974a4855a7f8 | 22 | 2. Integer - readInt |
| chrisisthefish | 0:974a4855a7f8 | 23 | */ |
| chrisisthefish | 0:974a4855a7f8 | 24 | |
| chrisisthefish | 0:974a4855a7f8 | 25 | float MSGEQ7::read(){ |
| chrisisthefish | 0:974a4855a7f8 | 26 | float reading = 0.0; |
| chrisisthefish | 0:974a4855a7f8 | 27 | _strobe = 0; |
| chrisisthefish | 0:974a4855a7f8 | 28 | wait_us(30); //Wait 30us for output to settle |
| chrisisthefish | 0:974a4855a7f8 | 29 | reading = _analog; |
| chrisisthefish | 0:974a4855a7f8 | 30 | _strobe = 1; |
| chrisisthefish | 0:974a4855a7f8 | 31 | return reading; |
| chrisisthefish | 0:974a4855a7f8 | 32 | } |
| chrisisthefish | 0:974a4855a7f8 | 33 | |
| chrisisthefish | 0:974a4855a7f8 | 34 | |
| chrisisthefish | 0:974a4855a7f8 | 35 | // readByte() reads the frequency values then stores them in unsigned char array freqDataByte, |
| chrisisthefish | 0:974a4855a7f8 | 36 | // with each frequency magnitude between 0 to 255 |
| chrisisthefish | 0:974a4855a7f8 | 37 | void MSGEQ7::readByte() { |
| chrisisthefish | 0:974a4855a7f8 | 38 | _reset = 1; |
| chrisisthefish | 0:974a4855a7f8 | 39 | _reset = 0; |
| chrisisthefish | 0:974a4855a7f8 | 40 | |
| chrisisthefish | 0:974a4855a7f8 | 41 | // Read all 7 frequency values and store them in the array |
| chrisisthefish | 0:974a4855a7f8 | 42 | for (int i = 0; i < 7; i++){ |
| chrisisthefish | 0:974a4855a7f8 | 43 | freqDataByte[i] = char(read() * 255); //Mult by 255 to properly scale reading |
| chrisisthefish | 0:974a4855a7f8 | 44 | } |
| chrisisthefish | 0:974a4855a7f8 | 45 | } |
| chrisisthefish | 0:974a4855a7f8 | 46 | |
| chrisisthefish | 0:974a4855a7f8 | 47 | |
| chrisisthefish | 0:974a4855a7f8 | 48 | // readInt() reads the frequency values, then stores them in integer array freqDataInt, |
| chrisisthefish | 0:974a4855a7f8 | 49 | // with each frequency magnitude between 0 to a value 'max' specified by the user |
| chrisisthefish | 0:974a4855a7f8 | 50 | void MSGEQ7::readInt(int max) { |
| chrisisthefish | 0:974a4855a7f8 | 51 | _reset = 1; |
| chrisisthefish | 0:974a4855a7f8 | 52 | _reset = 0; |
| chrisisthefish | 0:974a4855a7f8 | 53 | |
| chrisisthefish | 0:974a4855a7f8 | 54 | // Read all 7 frequency values and store them in the array |
| chrisisthefish | 0:974a4855a7f8 | 55 | for (int i = 0; i < 7; i++){ |
| chrisisthefish | 0:974a4855a7f8 | 56 | freqDataInt[i] = int(read() * max); //Mult by 'max' to properly scale reading |
| chrisisthefish | 0:974a4855a7f8 | 57 | } |
| chrisisthefish | 0:974a4855a7f8 | 58 | } |
MSGEQ7 Graphic Equalizer