I'm upgrading one of my projects that I did last year - A Christmas Light Spectrum Analyzer which used an MSGEQ7 chip. On that prototype, I had one potentiometer to set the threshold for all (7) bands. This year, I want to upgrade it to (7) potentiometers where each individual pot sets the threshold for its dedicated band.
I understand that there might be better methods than this, but I'm just tinkering with the idea and want to prove it out because I wasn't satisfied with one pot sets all.
I edited my old sketch and got it working, which was great. But being the amateur that I am, the code was very long and sloppy. So I felt the need to simplify the code and learn some new techniques... but I'm getting couple of errors.
Below is what I've written so far...
#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
int TRIM_POT_A[7] = {A1,A2,A3,A4,A5,A6,A7};
#define LED_LOW HIGH //was LOW
#define LED_HIGH LOW //was HIGH
#define CYCLE_DELAY 50 // set to 100 for mechanical relay, set to 50 for solid state relay
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]= {128,192,224,240,248,252,254,255};
byte setlevel[8]={128,64,32,16,8,4,2,1};
unsigned int valueMSG[7];
unsigned int potValue_A[7] = {0};
byte potSet_A[7] = {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,1);
/* and clear the display */
lc.clearDisplay(0);
}
void loop()
{
digitalWrite(msg7Strobe, HIGH);
digitalWrite(msg7RESET, HIGH);
//delayMicroseconds(0.1); //Reset Pluse Width 100nS Min
for (int x = 0 ; x < 7 ; x++)
potValue_A[x] = analogRead(TRIM_POT_A[x]);
potSet_A[x] = map(potValue_A[x], 0, 1024, 0, 8);
lc.setRow(0,[x]+1,setlevel[potSet_A[x]);
digitalWrite(msg7RESET, LOW);
delayMicroseconds(72); // Reset to Stobe Delay 72uS min
{
digitalWrite(msg7Strobe, LOW);
delayMicroseconds(36); //Output settling time 36us Min
int spectrumRead = analogRead(msg7DCout);
valueMSG[x] = map(spectrumRead, 0, 1024, 0, 8);
lc.setRow(0,x,level[valueMSG[x]]);
digitalWrite(msg7Strobe, HIGH);
delayMicroseconds(72); //Strobe to Strobe 72uS Min
//Set Lights
if(valueMSG[x] >= potSet_A[x])
{
digitalWrite(ledPins[x], LED_HIGH);
}
else
{
digitalWrite(ledPins[x], LED_LOW);
}
Serial.print("x = ");
Serial.println(x);
Serial.print("spectrumRead = ");
Serial.println(spectrumRead);
Serial.print("Potentiometer Value = ");
Serial.println(potValue_A[x]);
Serial.print("valueMSG[x] = ");
Serial.println(valueMSG[x]);
Serial.print("Potentiometer Setting = ");
Serial.println(potSet_A[x]]);
Serial.print('\n');
}
delay(CYCLE_DELAY); //Allow them to be on or off for a bit of time
}
And these are the errors that I'm getting...
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino: In function 'void loop()':
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino:78:12: error: 'x' was not declared in this scope
potSet_A[x] = map(potValue_A[x], 0, 1024, 0, 8);
^
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino: In lambda function:
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino:80:18: error: expected '{' before '+' token
lc.setRow(0,[x]+1,setlevel[potSet_A[x]);
^
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino: In function 'void loop()':
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino:80:18: error: no match for 'operator+' (operand types are 'loop()::<lambda()>' and 'int')
lc.setRow(0,[x]+1,setlevel[potSet_A[x]);
C:\Users\jalbe\OneDrive\Documents\Arduino\X-Mas Lights\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13\Update Musical_Lights_Controller_V13.ino:80:41: error: expected ']' before ')' token
lc.setRow(0,[x]+1,setlevel[potSet_A[x]);
^
exit status 1
Compilation error: 'x' was not declared in this scope
I'm a bit confused, because I thought I already declared 'x' in the scope.
The second error, I'm attempting to recall 'x' and add "1" but I'm I'm getting hung up here too.
What did I do wrong? Can you set my code straight?