Go Down

Topic: Fix my code? (Read 2 times) previous topic - next topic

techfreek

Feb 20, 2011, 08:14 pm Last Edit: Feb 20, 2011, 10:20 pm by techfreek Reason: 1
Hello!

I am working on code to analyze 6 frequencies of audio, and then turn that info into different brightnesses of led light. my setup involves an arduino uno, http://bliptronics.com/item.aspx?ItemID=116Blips stereo audio analyzer(takes the load off the arduino, and will make coding easier) and finally 2 RGB amplifiers from usLEDsupply to power 2 strips of RGB leds. (so total of 6 total channels) here is my code... I am willing to compensate you for what you think is reasonable

THANK YOU!

P.S. my code currently puts up a nice light bluish color(color doesn't matter, just that it puts up light with no music being played) and doesn't actually analyze the music... I started to add a feature that would fade out the lights if no music was playing... but it doesn't want to work... it compiles.... but the light blue does not fade...
Code: [Select]

int SpectrumLeft[6];
int ledintensity[6];
int ledintensity2[6];
int ledintensity3[6];
int analyze1[6];
int analyze2[6];
int fadespeed;
byte LED;
byte LED2;
byte spect;
byte db;

int led6 = 6;
int led7 = 7;
int led8 = 8;
int led9 = 9;
int led10 = 10;
int led11 = 11;

//have a fade out based on whether or not the music is playing use this for ideas http://arduino.cc/en/Tutorial/Calibration
//maybe something like run analyze levels, wait, analyze again, if they are same, fade (another function)

void setup () {
   pinMode(led6,OUTPUT);
   pinMode(led7,OUTPUT);
   pinMode(led8,OUTPUT);
   pinMode(led9,OUTPUT);
   pinMode(led10,OUTPUT);
   pinMode(led11,OUTPUT);
}
//Add a for loop so animation is smoother http://www.arduino.cc/en/Reference/For (this is all the basic code that the anaylzer needs)
void readSpectrum() {
 // Band 0 = Lowest Frequencies.
 byte Band;
 for(Band=0;Band <6; Band++){
   SpectrumLeft[Band] = analogRead(0); //left
   digitalWrite(4,HIGH);  //Strobe pin on the shield
   digitalWrite(4,LOW);    
 }
}

void same() {
 for(LED2=6; LED2 <12; LED2++){
     ledintensity2[LED2]=analyze1[LED2];
     delay(1);
     ledintensity2[LED2]=analyze2[LED2];
     if (analyze1[LED2]==analyze2[LED2]) {
       fadespeed = 75;
     }
      else {
       fadespeed = 0;
     }
  }
}

void fade() {
 if (fadespeed > 0) {
  for(LED2=6; LED2<12; LED2++)
   ledintensity2[LED2] - fadespeed;
 }
}

void loop () {
 for(LED=6; LED <12; LED++){
   for(spect=0; spect <7; spect++){
       for(LED2=6; LED2 <12; LED2++){
         readSpectrum();`
         ledintensity2[LED2]=(ledintensity[LED]+(25*SpectrumLeft[spect])); //this should in theory add the data of the analyzer to the base value for the lights, then send to the output the correct light level
         fade();
       }
     }
 }

 
   analogWrite(led6, ledintensity2[6]);
   analogWrite(led7, ledintensity2[7]);
   analogWrite(led8, ledintensity2[8]);
   analogWrite(led9, ledintensity2[9]);
   analogWrite(led10, ledintensity2[10]);
   analogWrite(led11, ledintensity2[11]);
}

Simpson_Jr

#1
Feb 20, 2011, 11:51 pm Last Edit: Feb 21, 2011, 12:03 am by Simpson_Jr Reason: 1
I don't know Blips, unfortunately can't help you with that.

There's one thing, Analogwrite uses PWM.
Two of the pins you used,  7 and 8, are not PWM-pins.

Quote
int led7 = 7;
int led8 = 8;


With a mega-board you can use pins 2-13, but the AnalogWrite-function should... only work on pins 3,5,6,9,10 and 11 with an Uno (or other 48/88/168/328-based board).

You can change your program to
int led7 = 3;
int led8 = 5;
and use the right pins on board accordingly.

I don't know whether this will solve the... problem, but I hope it's a step in the right direction ;-)


techfreek

Yes, it was a step in the right direction... still trying to figure out the control via music... Thank you for your help!

brucethehoon

Take a look at sparkfun.com and their latest product post.   It seems to be exactly what you're tying to do.  If nothing else perhaps you will get ideas!

techfreek


Take a look at sparkfun.com and their latest product post.   It seems to be exactly what you're tying to do.  If nothing else perhaps you will get ideas!

I saw that! It is pretty much exactly what I am going for! but... its more of a mobile version. I looked at the source code to see if it could help at all, but its not based on Arduino at all, so no luck :( thank you though!

Go Up