Good morning all,
I am currently working on a project for school, and have run into a brick wall. I want to take an audio input, run it through 5 filters, then each filter feeds it's own input pin, and use that input to turn on and off a corresponding output based on voltage levels.
I've managed to get the filters to pass the bands I want, and I've managed to have the Arduino turn on and off an output as I scroll through frequencies on a function generator. It's when I put the two together than I run into issues and since I'm also learning the language as I go, I have no idea where to go from here.
I did find GitHub - elmerfud/music_color: Arduino using analogue input w/FFT
But the code seems to be beyond my skill level at the moment, which is admittedly low...
Here is the code I have so far... a couple qualifiers.
-
I have the outputs defaulting to high because the MOSFETs I'm using seem to turn off the lights when a high is detected, and turn them on when a low is detected.
-
The number in the (outputValue > XXX) statements were simply me trying to troubleshoot and figure out what the program was doing.
Any and all help would be appreciated...
const int analogPin0 = 0; // Analog input pin for incoming signal
const int analogPin1 = 0;
const int analogPin2 = 0;
const int analogPin3 = 0;
const int analogPin4 = 0;
double sensorValue0 = 0;// value read from analog Pin
double sensorValue1 = 0;
double sensorValue2 = 0;
double sensorValue3 = 0;
double sensorValue4 = 0;
int outputValue0 = 0; // value output to the PWM (analog out)
int outputValue1 = 0;
int outputValue2 = 0;
int outputValue3 = 0;
int outputValue4 = 0;
void setup() {
pinMode(22, OUTPUT); //Set Pins 22, 24, 26, 28, 30 as output
pinMode(24, OUTPUT);
pinMode(26, OUTPUT);
pinMode(28, OUTPUT);
pinMode(30, OUTPUT);
}
void loop() {
digitalWrite (22, HIGH); // (Channel 1, Pin 22, Variable 0) clears a LOW signal on output 22
// read the analog in value:
sensorValue0 = analogRead(analogPin0); //reads the analog in value
// map it to the range of the analog out:
outputValue0 = map(sensorValue0, 0, 1023, 0, 255); //maps the incoming signal to an output
if (outputValue0 > 100 ) //compares the outgoing waveform to a set number to see if t's high enough
{
digitalWrite (22, LOW); //if high enough, then pin 22 is set LOW
}
else{
digitalWrite (22, HIGH); //otherwise it's HIGH
}
//delay so ADC can settle down
digitalWrite (24, HIGH); // (Channel 2, Pin 24, Variable 1) clears a LOW signal on output 24
// read the analog in value:
sensorValue1 = analogRead(analogPin1); //reads the analog in value
// map it to the range of the analog out:
outputValue1 = map(sensorValue1, 0, 1023, 0, 255); //maps the incoming signal to an output
if (outputValue1 > 255) //compares the outgoing waveform to a set number to see if t's high enough
{
digitalWrite (24, LOW); //if high enough, then pin 24 is set LOW
}
else{
digitalWrite (24, HIGH); //otherwise it's HIGH
}
{
digitalWrite (26, HIGH); // (Channel 3, Pin 26, Variable 2)clears a LOW signal on output 26
// read the analog in value:
sensorValue2 = analogRead(analogPin2); //reads the analog in value
// map it to the range of the analog out:
outputValue2 = map(sensorValue2, 0, 1023, 0, 255); //maps the incoming signal to an output
if (outputValue2 > 0) //compares the outgoing waveform to a set number to see if t's high enough
{
digitalWrite (26, LOW); //if high enough, then pin 26 is set LOW
}
else{
digitalWrite (26, HIGH); //otherwise it's HIGH
}
{
digitalWrite (28, HIGH); // (Channel 4, Pin 28, Variable 3) clears a LOW signal on output 28
// read the analog in value:
sensorValue3 = analogRead(analogPin3); //reads the analog in value
// map it to the range of the analog out:
outputValue3 = map(sensorValue3, 0, 1023, 0, 255); //maps the incoming signal to an output
if (outputValue3 > 0 ) //compares the outgoing waveform to a set number to see if t's high enough
{
digitalWrite (28, LOW); //if high enough, then pin 28 is set LOW
}
else{
digitalWrite (28, HIGH); //otherwise it's HIGH
}
{
digitalWrite (30, HIGH); // (Channel 5) clears a LOW signal on output 30
// read the analog in value:
sensorValue4 = analogRead(analogPin4); //reads the analog in value
// map it to the range of the analog out:
outputValue4 = map(sensorValue4, 0, 1023, 0, 255); //maps the incoming signal to an output
if (outputValue4 > 0 ) //compares the outgoing waveform to a set number to see if t's high enough
{
digitalWrite (30, LOW); //if high enough, then pin 30 is set LOW
}
else{
digitalWrite (30, HIGH); //otherwise it's HIGH
}
}
}
}
}
Edit: I have found this, Graphic Equalizer Display Filter - MSGEQ7 - COM-10468 - SparkFun Electronics? would this work any better since it only passes 1 frequency per channel instead of a bandwidth?