Pages: [1]   Go Down
Author Topic: LED Audio Reader Thing  (Read 188 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all,

So I am a college student working on a massive project, and I need for my LED array of sorts to read an audio imput and the change color based on Amplitude. Unfortunately, it is reading an amplitued of 0 always. Any help with code would be greatly appreciated. and remember im a civil engineering major, so electronics and programming isnt my forte!

Pinout: 36 RGB LEDS
 
Reds on Digital 2-5
Greens on 6-9
and Blues on 10-13

my Code:

//define the LEDs and audio input to their respective pins
#define RedLED2 2
#define RedLED3 3
#define RedLED4 4
#define RedLED5 5
#define GrnLED6 6
#define GrnLED7 7
#define GrnLED8 8
#define GrnLED9 9
#define BlueLED10 10
#define BlueLED11 11
#define BlueLED12 12
#define BlueLED13 13
#define audioInput A1

//declare variables
int inputAmplitude, aveAmpValue, stepValue;
int ampValue0, ampValue1, ampValue2, ampValue3, ampValue4, ampValue5, ampValue6, ampValue7;


void setup()
{
 
  //establish each LED pair as an output and turn it off
  for(int n = 2; n <= 13; n++)
  {
    pinMode(n, OUTPUT);
    digitalWrite(n, LOW);
  }
   
  //establish the music as an input
  pinMode(A1, INPUT);
 
  /*
  Serial port troubleshooting. All serial port behavior is commented out during run
  for faster LED response time.
  */
  Serial.begin(9600);
 


}


void loop()
{
 
   
   //read values of the audio coming in, average them, for use in the loop function
  ampValue0 = analogRead(audioInput);
  delay(5);
  ampValue1 = analogRead(audioInput);
  delay(5);
  ampValue2 = analogRead(audioInput);
  delay(5);
  ampValue3 = analogRead(audioInput);
  delay(5);
  ampValue4 = analogRead(audioInput);
  delay(5);
  ampValue5 = analogRead(audioInput);
  delay(5);
  ampValue6 = analogRead(audioInput);
  delay(5);
  ampValue7 = analogRead(audioInput);
  delay(5);
  aveAmpValue = (ampValue0 + ampValue1 + ampValue2 + ampValue3 + ampValue4 + ampValue5 + ampValue6 + ampValue7)/8;
  delay(5);
  /*
  Set the step value (how sensetive the lights are to the music) as a variable
  of the difference of the first amplitude value and the changing average
  amplitude value.
  */
  stepValue = 2*abs(aveAmpValue - inputAmplitude);
 
 
  //read the amplitude of the music
  inputAmplitude = analogRead(audioInput);
  Serial.println(inputAmplitude);
  //troubleshooting output to serial port
  Serial.print("inputAmplitude is: ");
  Serial.println(inputAmplitude);
   if (analogRead(audioInput) >= 50){
  /*
  Make the lights light up according to changes in the music. Do this by
  comparing the refreshing average amplitude to the first amplitude value
  recieved in setup. Based on how much this value is different (the step
  value), change the lights by either a large factor or a small one.
  */
  if (inputAmplitude<=10){digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, LOW);
    digitalWrite(GrnLED7, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(GrnLED9, LOW);
    digitalWrite(BlueLED10, LOW);
    digitalWrite(BlueLED11, LOW);
    digitalWrite(BlueLED12, LOW);
  } digitalWrite(BlueLED13, LOW);
  if(inputAmplitude <= aveAmpValue - stepValue)
  {
    digitalWrite(RedLED2, HIGH);
    digitalWrite(RedLED3, HIGH);
    digitalWrite(RedLED4, HIGH);
    digitalWrite(RedLED5, HIGH);
    digitalWrite(GrnLED6, LOW);
    digitalWrite(GrnLED7, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(GrnLED9, LOW);
    digitalWrite(BlueLED10, LOW);
    digitalWrite(BlueLED11, LOW);
    digitalWrite(BlueLED12, LOW);
    digitalWrite(BlueLED13, LOW);
  }
 
  else if(inputAmplitude <= aveAmpValue)
  {
    digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, LOW);
    digitalWrite(GrnLED7, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(BlueLED10, HIGH);
    digitalWrite(BlueLED11, HIGH);
    digitalWrite(BlueLED12, HIGH);
    digitalWrite(BlueLED13, HIGH);   
  }
     
  else if(inputAmplitude <= aveAmpValue + stepValue)
  {
    digitalWrite(RedLED2, HIGH);
    digitalWrite(RedLED3, HIGH);
    digitalWrite(RedLED4, HIGH);
    digitalWrite(RedLED5, HIGH);
    digitalWrite(GrnLED6, LOW);
    digitalWrite(GrnLED7, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(GrnLED9, LOW);
    digitalWrite(BlueLED10, LOW);
    digitalWrite(BlueLED11, LOW);
    digitalWrite(BlueLED12, LOW);
    digitalWrite(BlueLED13, LOW);
   
  }
   
  else if(inputAmplitude <= aveAmpValue + stepValue*2)
  {
    digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, HIGH);
    digitalWrite(GrnLED7, HIGH);
    digitalWrite(GrnLED8, HIGH);
    digitalWrite(GrnLED9, HIGH);
    digitalWrite(BlueLED10, LOW);
    digitalWrite(BlueLED11, LOW);
    digitalWrite(BlueLED12, LOW);
    digitalWrite(BlueLED13, LOW);
  }
 
  else if(inputAmplitude <= aveAmpValue + stepValue*3)
  {
    digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, HIGH);
    digitalWrite(GrnLED7, HIGH);
    digitalWrite(GrnLED8, HIGH);
    digitalWrite(GrnLED9, HIGH);
    digitalWrite(BlueLED10, LOW);
    digitalWrite(BlueLED11, LOW);
    digitalWrite(BlueLED12, LOW);
    digitalWrite(BlueLED13, LOW);
  }
 
  else if(inputAmplitude <= aveAmpValue + stepValue*4)
  {
    digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, HIGH);
    digitalWrite(GrnLED7, HIGH);
    digitalWrite(GrnLED8, HIGH);
    digitalWrite(GrnLED9, HIGH);
    digitalWrite(BlueLED10, LOW);
    digitalWrite(BlueLED11, LOW);
    digitalWrite(BlueLED12, LOW);
    digitalWrite(BlueLED13, LOW);
  }
 
  else if(inputAmplitude <= aveAmpValue + stepValue*5)
  {
    digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, LOW);
    digitalWrite(GrnLED7, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(GrnLED9, LOW);
    digitalWrite(BlueLED10, HIGH);
    digitalWrite(BlueLED11, HIGH);
    digitalWrite(BlueLED12, HIGH);
    digitalWrite(BlueLED13, HIGH);
  }
 
  else if(inputAmplitude <= aveAmpValue + stepValue*6)
  {
    digitalWrite(RedLED2, LOW);
    digitalWrite(RedLED3, LOW);
    digitalWrite(RedLED4, LOW);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, LOW);
    digitalWrite(GrnLED7, LOW);
    digitalWrite(GrnLED8, LOW);
    digitalWrite(GrnLED9, LOW);
    digitalWrite(BlueLED10, HIGH);
    digitalWrite(BlueLED11, HIGH);
    digitalWrite(BlueLED12, HIGH);
    digitalWrite(BlueLED13, HIGH);
  }
   
  else
  {
    digitalWrite(RedLED2, HIGH);
    digitalWrite(RedLED3, HIGH);
    digitalWrite(RedLED4, HIGH);
    digitalWrite(RedLED5, LOW);
    digitalWrite(GrnLED6, HIGH);
    digitalWrite(GrnLED7, HIGH);
    digitalWrite(GrnLED8, HIGH);
    digitalWrite(GrnLED9, LOW);
    digitalWrite(BlueLED10, HIGH);
    digitalWrite(BlueLED11, HIGH);
    digitalWrite(BlueLED12, HIGH);
    digitalWrite(BlueLED13, LOW);
  }
   }
  else{
    digitalWrite(RedLED2, HIGH);
    digitalWrite(RedLED3, HIGH);
    digitalWrite(RedLED4, HIGH);
    digitalWrite(RedLED5, HIGH);
    digitalWrite(GrnLED6, HIGH);
    digitalWrite(GrnLED7, HIGH);
    digitalWrite(GrnLED8, HIGH);
    digitalWrite(GrnLED9, HIGH);
    digitalWrite(BlueLED10, HIGH);
    digitalWrite(BlueLED11, HIGH);
    digitalWrite(BlueLED12, HIGH);
    digitalWrite(BlueLED13, HIGH);
    }
 delay(20);
 
}

Thanks Again!
Logged

West Yorkshire, UK
Offline Offline
God Member
*****
Karma: 17
Posts: 703
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, if you want any chance of some help on this, you really need to read the "How to use this forum - please read." message first. You clearly haven't and I bet that's why no-one has responded yet.

You need to edit your original post, enclose your sketch within code tags (see the # button) and explain your circuit much more clearly, including a schematic or at least a clear picture. Your brief description is confusing and seems to contradict itself (e.g. the number of LEDs). The schematic can be hand-drawn as long as it is clear (as a civil engineering student you should understand how important diagrams are).

You say the amplitude reading is always zero, which points to a problem with the part of the circuit that feeds the audio signal to the Arduino, and you have told us nothing about that yet.

Paul
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31343
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and remember im a civil engineering major
How can we remember this because this is your first post so by definition you have not told us about this fact before.

Yes we are a very literal lot here, computer programming demands that.  smiley
Logged

Pages: [1]   Go Up
Jump to: