please copy the whole error message to the forum
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino: In function 'void ReadMSGEQ7()':
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:45:48: error: invalid types 'int[int]' for array subscript
if (tmpVals[iSample] < tmpsVals[iSample - 1])
^
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:62:24: error: invalid types 'int[int]' for array subscript
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
^
exit status 1
Compilation error: invalid types 'int[int]' for array subscript
Sorry, but you have some mess in the code.
MSGEQ7Amplitude is defined as single integer, but you try to use it as array:
And what's means iBand as an index? It defined as 0 in the start of the code and not changed anywhere.
After that, note this loop:
you iterate the iBand in the loop, but using iSample as index for array? All values will be stored in the same tmpVals[0] array element. Is it what you intended?
Umm... No.
I copied 95% of this code from...
https://www.eeweb.com/handling-noise-when-working-with-the-msgeq7-audio-spectrum-analyzer/
The original code didn't declare any of the variables, so I attempted to declare all the variables the best that I could.
How should I declare "MSGEQ7Amplitude" and "iband" then?
Your code is very far from the original. You mixed things up, rearranged the brackets and lost the logic.
And again, as in previous thread, you lost the MSGEq7 strobe signal in the code....
Oh, shoot... good catch with the missing strobe signal! Thanks, I just added those couple of missing lines.
OK, I double checked my code compared to the original, and ran the code but got this error.
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino: In function 'void ReadMSGEQ7()':
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:53:50: error: invalid types 'int[int]' for array subscript
if (tmpVals[iSample] < tmpsVals[iSample - 1])
^
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:70:26: error: invalid types 'int[uint8_t {aka unsigned char}]' for array subscript
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
^
exit status 1
Compilation error: invalid types 'int[int]' for array subscript
Here's the updated code. Where did I go wrong this time?
void ReadMSGEQ7()
{
#define msg7RESET 13
#define msg7DCout A0
#define msg7Strobe 9
const int NUM_SAMPLES = 5;
unsigned int NUM_MSGEQ7_BANDS[7];
int iSample = 0;
int tmpVAL = 0;
int tmpsVals = 0;
int MSGEQ7Amplitude = 0;
int iBand = 0;
uint16_t tmpVal;
uint16_t tmpVals[NUM_SAMPLES];
//Pulse the reset signal to latch the current MSGEQ7 values
digitalWrite(msg7RESET, HIGH);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(80); // Reset to Stobe Delay 72uS MIN
// Cycle through the MSGEQ7's seven spectrum bands
for (uint8_t iBand = 0; iBand < NUM_MSGEQ7_BANDS; iBand++)
{
digitalWrite(msg7Strobe,LOW); // Read the current band (then increment to next band)
delayMicroseconds(40); // Wait for outputs to settle (36uS MIN)
// Start of modifications
// Gather Samples
for (uint8_t iSample = 0; iSample < NUM_SAMPLES; iSample++)
{
tmpVals[iSample] = analogRead(msg7DCout);
}
//Ripple largest value up to upper sample slot
for (uint8_t iSample = 0; iSample < (NUM_SAMPLES - 1); iSample++)
{
if (tmpVals[iSample] > tmpVals[iSample + 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample + 1];
tmpVals[iSample + 1] = tmpVal;
}
}
//Ripple smallest value down to lower sample slot
//Start at [NUM_SAMPLES - 2]; we already know that [NUM_SAMPLES - 1] contains the largest value
for (uint8_t iSample = (NUM_SAMPLES - 2); iSample > 0; iSample--)
{
if (tmpVals[iSample] < tmpsVals[iSample - 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample - 1];
tmpVals[iSample - 1] = tmpVal;
}
}
//Average out the values excluding the outliers in the lower and upper slots
tmpVal = 0;
for (uint8_t iSample = 1; iSample < (NUM_SAMPLES - 1); iSample++)
{
tmpVal = tmpVal + tmpVals[iSample];
}
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
//End of modifications
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(40); // Pad Delay to meet MIN strobe to Strobe time (72us)
}
}
Are you feeding directly into the Arduino ADC pins or into 3 separate MSGEQ7 ICs?
This circuit:

is beyond terrible for proper loading of well designed audio line output impedance.
Using standard lineout jacks, one can guess around 75-100 Ohms. But, the Z could be as high as 600-900 Ohms (at 1000 Hz.) Therefore,
using a linear 1K pot (rheostat + 100 Ohm serial resistor for safety) for adjusting input Z would be beneficial to lower the noise floor: reduce resistance to eliminate noise.
Next, use quality shielded cable from audio source to the MSGEQ7 and ground the shields appropriately ... if you do not know how:
Grounding and Shielding for your DIY Audio Projects
Maybe test something like this:
$ 1 0.000005 10.20027730826997 50 5 50 5e-11
r 64 160 208 160 0 100
174 208 160 224 304 1 1000 0.5 Resistance
w 208 160 304 160 0
w 224 240 304 240 0
w 304 160 336 160 0
c 336 160 416 160 0 1e-7 -2.897278913921169 0.001
r 416 160 416 320 0 10000
w 208 320 416 320 0
w 304 240 304 160 0
g 416 320 416 368 0 0
170 64 160 32 160 2 100 10000 5 10
p 416 160 512 160 1 1 1
Unfortunately, this is the circuit that I built. I'll keep this in mind for my next project, but for now, its too late - I'm all soldered up so I'm looking for a software solution instead.
As mentioned earlier... I double checked my code compared to the original from https://www.eeweb.com/handling-noise-when-working-with-the-msgeq7-audio-spectrum-analyzer/, and ran the code but got this error.
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino: In function 'void ReadMSGEQ7()':
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:53:50: error: invalid types 'int[int]' for array subscript
if (tmpVals[iSample] < tmpsVals[iSample - 1])
^
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:70:26: error: invalid types 'int[uint8_t {aka unsigned char}]' for array subscript
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
^
exit status 1
Compilation error: invalid types 'int[int]' for array subscript
Here's the updated code. Where did I go wrong this time?
void ReadMSGEQ7()
{
#define msg7RESET 13
#define msg7DCout A0
#define msg7Strobe 9
const int NUM_SAMPLES = 5;
unsigned int NUM_MSGEQ7_BANDS[7];
int iSample = 0;
int tmpVAL = 0;
int tmpsVals = 0;
int MSGEQ7Amplitude = 0;
int iBand = 0;
uint16_t tmpVal;
uint16_t tmpVals[NUM_SAMPLES];
//Pulse the reset signal to latch the current MSGEQ7 values
digitalWrite(msg7RESET, HIGH);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(80); // Reset to Stobe Delay 72uS MIN
// Cycle through the MSGEQ7's seven spectrum bands
for (uint8_t iBand = 0; iBand < NUM_MSGEQ7_BANDS; iBand++)
{
digitalWrite(msg7Strobe,LOW); // Read the current band (then increment to next band)
delayMicroseconds(40); // Wait for outputs to settle (36uS MIN)
// Start of modifications
// Gather Samples
for (uint8_t iSample = 0; iSample < NUM_SAMPLES; iSample++)
{
tmpVals[iSample] = analogRead(msg7DCout);
}
//Ripple largest value up to upper sample slot
for (uint8_t iSample = 0; iSample < (NUM_SAMPLES - 1); iSample++)
{
if (tmpVals[iSample] > tmpVals[iSample + 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample + 1];
tmpVals[iSample + 1] = tmpVal;
}
}
//Ripple smallest value down to lower sample slot
//Start at [NUM_SAMPLES - 2]; we already know that [NUM_SAMPLES - 1] contains the largest value
for (uint8_t iSample = (NUM_SAMPLES - 2); iSample > 0; iSample--)
{
if (tmpVals[iSample] < tmpsVals[iSample - 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample - 1];
tmpVals[iSample - 1] = tmpVal;
}
}
//Average out the values excluding the outliers in the lower and upper slots
tmpVal = 0;
for (uint8_t iSample = 1; iSample < (NUM_SAMPLES - 1); iSample++)
{
tmpVal = tmpVal + tmpVals[iSample];
}
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
//End of modifications
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(40); // Pad Delay to meet MIN strobe to Strobe time (72us)
}
}
Almost the same as previous
-
MSGEQ7Amplitudeis defined as single integer, but you try to use it as array -
unsigned int NUM_MSGEQ7_BANDS[7]defined as array, but used as single variable
Maybe you mixed them up?
Try to change definitions like this:
unsigned int NUM_MSGEQ7_BANDS = 7;
int MSGEQ7Amplitude[7] = {0};
Ok, I gave that a shot but still no go.
Error output states:
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino: In function 'void ReadMSGEQ7()':
C:\Users\jalbe\OneDrive\Desktop\X-Mas Lights\Update Musical_Lights_Controller_V3\Update Musical_Lights_Controller_V3.ino:56:50: error: invalid types 'int[int]' for array subscript
if (tmpVals[iSample] < tmpsVals[iSample - 1])
^
exit status 1
Compilation error: invalid types 'int[int]' for array subscript
Could you show whole sketch?
void ReadMSGEQ7()
{
#define msg7RESET 13
#define msg7DCout A0
#define msg7Strobe 9
const int NUM_SAMPLES = 5;
// unsigned int NUM_MSGEQ7_BANDS[7];
unsigned int NUM_MSGEQ7_BANDS = 7;
int iSample = 0;
int tmpVAL = 0;
int tmpsVals = 0;
// int MSGEQ7Amplitude = 0;
int MSGEQ7Amplitude[7] = {0};
int iBand = 0;
uint16_t tmpVal;
uint16_t tmpVals[NUM_SAMPLES];
//Pulse the reset signal to latch the current MSGEQ7 values
digitalWrite(msg7RESET, HIGH);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(80); // Reset to Stobe Delay 72uS MIN
// Cycle through the MSGEQ7's seven spectrum bands
for (uint8_t iBand = 0; iBand < NUM_MSGEQ7_BANDS; iBand++)
{
digitalWrite(msg7Strobe,LOW); // Read the current band (then increment to next band)
delayMicroseconds(40); // Wait for outputs to settle (36uS MIN)
// Start of modifications
// Gather Samples
for (uint8_t iSample = 0; iSample < NUM_SAMPLES; iSample++)
{
tmpVals[iSample] = analogRead(msg7DCout);
}
//Ripple largest value up to upper sample slot
for (uint8_t iSample = 0; iSample < (NUM_SAMPLES - 1); iSample++)
{
if (tmpVals[iSample] > tmpVals[iSample + 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample + 1];
tmpVals[iSample + 1] = tmpVal;
}
}
//Ripple smallest value down to lower sample slot
//Start at [NUM_SAMPLES - 2]; we already know that [NUM_SAMPLES - 1] contains the largest value
for (uint8_t iSample = (NUM_SAMPLES - 2); iSample > 0; iSample--)
{
if (tmpVals[iSample] < tmpsVals[iSample - 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample - 1];
tmpVals[iSample - 1] = tmpVal;
}
}
//Average out the values excluding the outliers in the lower and upper slots
tmpVal = 0;
for (uint8_t iSample = 1; iSample < (NUM_SAMPLES - 1); iSample++)
{
tmpVal = tmpVal + tmpVals[iSample];
}
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
//End of modifications
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(40); // Pad Delay to meet MIN strobe to Strobe time (72us)
}
}
Should tmpsVals[... be tmpVals[...? That is, remove the extra 's'
Not according to the original code...
https://www.eeweb.com/handling-noise-when-working-with-the-msgeq7-audio-spectrum-analyzer/
My eyes might be old, and it's starting to be late where I am, but the code you linked to is still saying '...< tmpVals ' and not '...<tmpsVals' like you have in your own code. The screenshot is from the page you linked to.

Oh! I see it now... ok. Thank you!
Now I get a new error...
C:\Users\jalbe\AppData\Local\Temp\cc2unOLI.ltrans0.ltrans.o: In function `main':
C:\Users\jalbe\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:43: undefined reference to `setup'
C:\Users\jalbe\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
void ReadMSGEQ7()
{
#define msg7RESET 13
#define msg7DCout A0
#define msg7Strobe 9
const int NUM_SAMPLES = 5;
// unsigned int NUM_MSGEQ7_BANDS[7];
unsigned int NUM_MSGEQ7_BANDS = 7;
int iSample = 0;
int tmpVAL = 0;
int tmpsVals = 0;
// int MSGEQ7Amplitude = 0;
int MSGEQ7Amplitude[7] = {0};
int iBand = 0;
uint16_t tmpVal;
uint16_t tmpVals[NUM_SAMPLES];
//Pulse the reset signal to latch the current MSGEQ7 values
digitalWrite(msg7RESET, HIGH);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(80); // Reset to Stobe Delay 72uS MIN
// Cycle through the MSGEQ7's seven spectrum bands
for (uint8_t iBand = 0; iBand < NUM_MSGEQ7_BANDS; iBand++)
{
digitalWrite(msg7Strobe,LOW); // Read the current band (then increment to next band)
delayMicroseconds(40); // Wait for outputs to settle (36uS MIN)
// Start of modifications
// Gather Samples
for (uint8_t iSample = 0; iSample < NUM_SAMPLES; iSample++)
{
tmpVals[iSample] = analogRead(msg7DCout);
}
//Ripple largest value up to upper sample slot
for (uint8_t iSample = 0; iSample < (NUM_SAMPLES - 1); iSample++)
{
if (tmpVals[iSample] > tmpVals[iSample + 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample + 1];
tmpVals[iSample + 1] = tmpVal;
}
}
//Ripple smallest value down to lower sample slot
//Start at [NUM_SAMPLES - 2]; we already know that [NUM_SAMPLES - 1] contains the largest value
for (uint8_t iSample = (NUM_SAMPLES - 2); iSample > 0; iSample--)
{
if (tmpVals[iSample] < tmpVals[iSample - 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample - 1];
tmpVals[iSample - 1] = tmpVal;
}
}
//Average out the values excluding the outliers in the lower and upper slots
tmpVal = 0;
for (uint8_t iSample = 1; iSample < (NUM_SAMPLES - 1); iSample++)
{
tmpVal = tmpVal + tmpVals[iSample];
}
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
//End of modifications
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(40); // Pad Delay to meet MIN strobe to Strobe time (72us)
}
}
I'm very new to Arduino myself, but whenever I create a new sketch in the IDE I automatically get the functions setup() and loop(). The error message you now receive suggests you miss these functions.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Each arduini sketch must contains two predefined procedures : setup() and loop().
Your code contains
void ReadMSGEQ7()
procedure only.
It seems that you are missing the most basic programming knowledge. I recommend you put the sketch aside for now and read some book on arduino for beginners, otherwise you will never finish your project
b707 - I've mentioned that I'm an amateur several times throughout my posts - this should be no surprise. I've bought and read the book Arduino Workshop - but until I actually apply the skills, I find it difficult to retain all the information I've read. Again, I'm not a programmer, I'm just a hobbyist.
With that in mind, I have applied the void setup() and void loop() into my sketch and am pleased that there are no further errors. Didn't realize this was a requirement. Thanks so much for your help.
OK... So now I want to integrate this code into my existing/working project code. Can you guide me on how I can do that?
This is my existing/working project code:
/*
* Muscial Lights Controller V2
* Just Barran 2021
* project video At
* www.youtube.com/c/justbarran
* Like Share Subscribe
*/
#include "LedControl.h"
#define msg7RESET 13
#define msg7Strobe 9
#define msg7DCout A0
#define maxDataIn 10
#define maxLoad 11
#define maxCLK 12
#define led1 2
#define led2 3
#define led3 4
#define led4 5
#define led5 6
#define led6 7
#define led7 8
#define TRIM_POT A1
#define LED_LOW HIGH //was LOW - Shaun Jalbert
#define LED_HIGH LOW //was HIGH - Shaun Jalbert
#define CYCLE_DELAY 100 // was 50 - set to 100 needed for relay to prevent constant switching
LedControl lc=LedControl(maxDataIn,maxCLK,maxLoad,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
byte ledPins[7]= {led1,led2,led3,led4,led5,led6,led7};
byte level[8]= {B10000000,B11000000,B11100000,B11110000,B11111000,B11111100,B11111110,B11111111};
byte setlevel[8]={B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001};
unsigned int valueMSG[7];
unsigned int potValue=0;
byte potSet = 0;
void setup() {
Serial.begin(115200);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
pinMode(msg7RESET, OUTPUT);
pinMode(msg7Strobe, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
digitalWrite(msg7Strobe, HIGH);
digitalWrite(msg7RESET, LOW);
digitalWrite(led1, LED_LOW);
digitalWrite(led2, LED_LOW);
digitalWrite(led3, LED_LOW);
digitalWrite(led4, LED_LOW);
digitalWrite(led5, LED_LOW);
digitalWrite(led6, LED_LOW);
digitalWrite(led7, LED_LOW);
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,5);
/* and clear the display */
lc.clearDisplay(0);
}
void loop()
{
digitalWrite(msg7Strobe, HIGH);
digitalWrite(msg7RESET, HIGH);
delayMicroseconds(0.1); //Reset Pluse Width 100nS Min
potValue = analogRead(TRIM_POT);
potSet = map(potValue, 0, 1023, 0, 8);
lc.setRow(0,7,setlevel[potSet]);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(72); // Reset to Stobe Delay 72uS min
for (int x = 0 ; x < 7 ; x++)
{
digitalWrite(msg7Strobe, LOW);
delayMicroseconds(36); //Output settling time 36us Min
Serial.print("x = ");
Serial.println(x); //Write the pulse index to serial - Shaun Jalbert
//Read MSG Value
int spectrumRead = analogRead(msg7DCout);
Serial.print("spectrumRead = ");
Serial.println(spectrumRead); //Write the value 'spectrumRead' to serial - Shaun Jalbert
Serial.print("Potentiometer Value = ");
Serial.println(potValue); //Write the value 'potValue' to serial - Shaun Jalbert
valueMSG[x] = map(spectrumRead, 0, 1023, 0, 8);
Serial.print("valueMSG[x] = ");
Serial.println(valueMSG[x]); //Write the value 'valueMSG[x]' to serial - Shaun Jalbert
Serial.print("Potentiometer Setting = ");
Serial.println(potSet); //Write the value 'potSet' to serial - Shaun Jalbert
Serial.print('\n'); //Write to the next line for formatting the serial output - Shaun Jalbert
lc.setRow(0,x,level[valueMSG[x]]);
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(72); //Strobe to Strobe 72uS Min //was 40 set to 80 - Shaun Jalbert
//Set Lights
if(valueMSG[x]>=potSet)
{
digitalWrite(ledPins[x], LED_HIGH);
}
else
{
digitalWrite(ledPins[x], LED_LOW);
}
}
delay(CYCLE_DELAY); //Allow them to be on or off for a bit of time
}
void test()
{
lc.setRow(0,0,level[0]);
lc.setRow(0,1,level[1]);
lc.setRow(0,2,level[2]);
lc.setRow(0,3,level[3]);
lc.setRow(0,4,level[4]);
lc.setRow(0,5,level[5]);
lc.setRow(0,6,level[6]);
lc.setRow(0,7,level[7]);
delay(1000);
lc.clearDisplay(0);
for(int i = 0; i<8;i++)
{
lc.setRow(0,0,level[i]);
delay(500);
}
}
This is the noise cancelation code we resolved earlier in this thread.
#define msg7RESET 13
#define msg7DCout A0
#define msg7Strobe 9
void setup()
{
}
void loop()
{
const int NUM_SAMPLES = 5;
// unsigned int NUM_MSGEQ7_BANDS[7];
unsigned int NUM_MSGEQ7_BANDS = 7;
int iSample = 0;
int tmpVAL = 0;
int tmpsVals = 0;
// int MSGEQ7Amplitude = 0;
int MSGEQ7Amplitude[7] = {0};
int iBand = 0;
uint16_t tmpVal;
uint16_t tmpVals[NUM_SAMPLES];
//Pulse the reset signal to latch the current MSGEQ7 values
digitalWrite(msg7RESET, HIGH);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(80); // Reset to Stobe Delay 72uS MIN
// Cycle through the MSGEQ7's seven spectrum bands
for (uint8_t iBand = 0; iBand < NUM_MSGEQ7_BANDS; iBand++)
{
digitalWrite(msg7Strobe,LOW); // Read the current band (then increment to next band)
delayMicroseconds(40); // Wait for outputs to settle (36uS MIN)
// Start of modifications
// Gather Samples
for (uint8_t iSample = 0; iSample < NUM_SAMPLES; iSample++)
{
tmpVals[iSample] = analogRead(msg7DCout);
}
//Ripple largest value up to upper sample slot
for (uint8_t iSample = 0; iSample < (NUM_SAMPLES - 1); iSample++)
{
if (tmpVals[iSample] > tmpVals[iSample + 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample + 1];
tmpVals[iSample + 1] = tmpVal;
}
}
//Ripple smallest value down to lower sample slot
//Start at [NUM_SAMPLES - 2]; we already know that [NUM_SAMPLES - 1] contains the largest value
for (uint8_t iSample = (NUM_SAMPLES - 2); iSample > 0; iSample--)
{
if (tmpVals[iSample] < tmpVals[iSample - 1])
//Swap the values
{
tmpVal = tmpVals[iSample];
tmpVals[iSample] = tmpVals[iSample - 1];
tmpVals[iSample - 1] = tmpVal;
}
}
//Average out the values excluding the outliers in the lower and upper slots
tmpVal = 0;
for (uint8_t iSample = 1; iSample < (NUM_SAMPLES - 1); iSample++)
{
tmpVal = tmpVal + tmpVals[iSample];
}
MSGEQ7Amplitude[iBand] = tmpVAL / (NUM_SAMPLES - 2);
//End of modifications
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(40); // Pad Delay to meet MIN strobe to Strobe time (72us)
}
}
Is it just as simple as copying and pasting it in or is there more to it?
