Hello to all,
I have used a code for a mono led vu meter and now i want to transform it into a stereo vu meter but i cannot succeed. I have searched on google but i find examples only for led strips and others. I want to use simple led's.
The original code is:
int led[5] = { 3, 4, 5, 6, 7}; /* Assign the pins for the leds*/
int right[5] = { 8, 9, 10, 11, 12}; /* Assign the pins for the leds*/
int leftChannel = 0; // left channel input
int rightChannel = 1; // left channel input
int left, right, i, e;
void setup()
{
for (i = 0; i < 10; i++)
pinMode(led[i], OUTPUT);
for (e = 0; e < 10; e++)
pinMode(led[e], OUTPUT);
}
void loop()
{
left = analogRead(leftChannel); // read the left channel
right = analogRead(rightChannel); // read the left channel
left = left / 30; // adjusts the sensitivity
right = right / 30; // 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[i], LOW);
}
}
else
{
for (i = 0; i < left; i++) // turn on the leds up to the volume level
{
digitalWrite(led[i], HIGH);
}
for(i = i; i < 10; i++) // turn off the leds above the voltage level
{
digitalWrite(led[i], LOW);
}
}
//right
if (right == 0) // if the volume is 0 then turn off all leds
{
for(e = 0; e < 10; e++)
{
digitalWrite(right[i], LOW);
}
}
else
{
for (e = 0; e < right; e++) // turn on the leds up to the volume level
{
digitalWrite(right[i], HIGH);
}
for(e = e; e < 10; e++) // turn off the leds above the voltage level
{
digitalWrite(led[i], LOW);
}
}
}
Now, the code modified by me (i want only 5 led's per channel) is:
int led[5] = { 3, 4, 5, 6, 7}; /* Assign the pins for the leds*/
int right[5] = { 8, 9, 10, 11, 12}; /* Assign the pins for the leds*/
int leftChannel = 0; // left channel input
int rightChannel = 1; // left channel input
int left, i;
int right, e;
void setup()
{
for (i = 0; i < 10; i++)
pinMode(led[i], OUTPUT);
for (e = 0; e < 10; e++)
pinMode(led[e], OUTPUT);
}
void loop()
{
left = analogRead(leftChannel); // read the left channel
right = analogRead(rightChannel); // read the left channel
left = left / 30; // adjusts the sensitivity
right = right / 30; // 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[i], LOW);
}
}
else
{
for (i = 0; i < left; i++) // turn on the leds up to the volume level
{
digitalWrite(led[i], HIGH);
}
for(i = i; i < 10; i++) // turn off the leds above the voltage level
{
digitalWrite(led[i], LOW);
}
}
//right
if (right == 0) // if the volume is 0 then turn off all leds
{
for(e = 0; e < 10; e++)
{
digitalWrite(right[i], LOW);
}
}
else
{
for (e = 0; e < right; e++) // turn on the leds up to the volume level
{
digitalWrite(right[i], HIGH);
}
for(e = e; e < 10; e++) // turn off the leds above the voltage level
{
digitalWrite(led[i], LOW);
}
}
}
but i get all kind of int errors.
Could someone PLEASE help me?
Thank you all in advance