# Stereo LED VU meter

Hi

I’ve made a stereo vu meter but the problem is when the music is on/off all the leds keep lit. I’ve no idea what the problem is… Here’s the code that I’ve:

int led[10] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int led1[10] = { 34, 36, 38, 40, 42, 44, 46, 48, 50, 52};

int leftChannel = A0; // left channel input
int rightChannel = A1; // left channel input

int left, i;
int right, e;

void setup()
{
for (i = 0; i < 10; i++)
pinMode(led*, OUTPUT);*
for (e = 0; e < 10; e++)
pinMode(led[e], OUTPUT);
}
void loop()
{
left = left /20; // adjusts the sensitivity
right = right / 12; // adjusts the sensitivity
//left = 1500; // uncomment to test all leds light.
//left = 0; // uncomment to check the leds are not lit when the input is 0.
//left
if (left == 0) // if the volume is 0 then turn off all leds
{
for(i = 0; i < 10; 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 < 10; i++) // turn off the leds above the voltage level
{
digitalWrite(led*, LOW);*
}
}
//right
if (right == 0) // if the volume is 0 then turn off all leds
{
for(e = 0; e < 10; e++)
{
digitalWrite(led1[e], LOW);
}
}
else
{
for (e = 0; e < right; e++) // turn on the leds up to the volume level
{
digitalWrite(led1[e], HIGH);
}
for(e = e; e < 10; e++) // turn off the leds above the voltage level
{
digitalWrite(led1[e], LOW);
}
}
}
Regards
Xander
Stereo_VUmeter.zip (3.54 KB)

Why are right channel LEDs addressed with array notation while the left channel LEDs are not?

The compiler doesn't care about what you name your variables. It would help *you * to have more descriptive variable names.

And code tags on your post.

``````for(i = 0; i < 10; i++)
{
digitalWrite(led, LOW);
}
``````

In several places you are not using i when you do the digitalWrite. led is an array so led might work better.
Steve

slipstick:
In several places you are not using i when you do the digitalWrite. led is an array so led might work better.[/quote]
That is from lack of code tags. Presumably it actually says led[ i ], but the [ i ] falls out and makes the rest italic.