Go Down

Topic: Sound activated lights/ Multiple Inputs and outputs (Read 4723 times) previous topic - next topic

ElectroNewb

Aug 22, 2012, 05:23 pm Last Edit: Aug 22, 2012, 05:45 pm by ElectroNewb Reason: 1
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 https://github.com/elmerfud/music_color

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.

1. 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.

2. 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...

Code: [Select]

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, https://www.sparkfun.com/products/10468? would this work any better since it only passes 1 frequency per channel instead of a bandwidth?

Lakes

Much easier to use that chip, plenty of examples, and you free all those 5 pins you used for the inputs.

ElectroNewb

#2
Aug 22, 2012, 07:29 pm Last Edit: Aug 22, 2012, 07:56 pm by ElectroNewb Reason: 1
Much appreciated, with the bit of reading I did on that chip, if I understand correctly. With each change in frequency, there's a corresponding change in the voltage. So I could simply read what voltage is coming in, and turn on and off the outputs as the voltage changes?

That sounds a lot easier than my initial plan...

Also, is there anything I can do to save the initial plan, I've ordered the chips but want to keep working on this until they get here since I don't have a lot of time. And if they get lost in the mail or something, I don't want to be depending on those chips.


ElectroNewb

Much appreciated Lakes, this path is showing more and more promise as I research it.

ElectroNewb

Once again Lakes, thanks... I actually got this up and running with the MSGEQ7, and it went flawlessly at the presentation for school. I'm getting a video of it today and I'll find a place to put it later..

I have a new question for anyone, as I have no idea where to even start for this.

I have this project so that you can plug it into anything with a headphone jack, so I can play it off of my phone, the problem is the speakers. I have a splitter that feeds the lights as well as a set of speakers when it plays, depending on what set of speakers I use (i have 2) the lights will work with one set, but stay on with the other set... the music is unaffected.

Anyone know what might be causing that?

Go Up