Hi Folks,
The following is some code I adopted from a website for my LED VU meter. However, one of the issues is that the Sensitivity is sort of HARD-CODED. Is there a way to incorporate a more dynamic calibration going on from the audio signal depending on the song. Imagine a variable standing for 20 (the calibration factor) and changing depending on the signal strength of the cube.
You can view the "signal" strength coming through from A0 from the serial print screen and values usually are around 200 ish for me when driven by an Ipod.
int led[6] = { 3, 4, 5, 6, 7, 8}; // Assign the pins for the leds
int leftChannel = A0; // left channel input
int left, i;
void setup()
{
for (i = 0; i < 6; i++) // Tell the arduino that the leds are digital outputs
pinMode(led*, OUTPUT);*
Serial.begin(9600);
}
void loop()
{
left = analogRead(leftChannel); // read the left channel
Serial.println(left);
Serial.print("\t");
left = left / 20; // adjusts the sensitivity
Serial.println(left);
Serial.print("\t");
- if (left == 0) // if the volume is 0 then turn off all leds*
- {*
- for(i = 0; i < 6; i++)*
- {*
_ digitalWrite(led*, LOW);_
_ }_
_ }*_
* else*
* {*
* for (i = 0; i < left; i++) // turn on the leds up to the volume level*
* {*
_ digitalWrite(led*, HIGH);
}*_
* for(i = i; i < 6; i++) // turn off the leds above the voltage level*
* {*
_ digitalWrite(led*, LOW);
}
}
}*_