int sound[4];
int soundav;
int sensorPin = 9;
int sensorValue = 0;
const int inputPIN = 8; //audio input pin, you have to amplify your output to max 5V
const int firstLED= 34; //first output pin for the leds
const int lastLED = 53; //last output pin for the leds
int leds;
int x;
int y;
void setup ()
{
pinMode (inputPIN, INPUT); // put input pin in input state
for (int a=firstLED; a <=lastLED; a++){ // loop through all the outputpins and put them in output state
pinMode(a, OUTPUT);
}
leds = (lastLED - firstLED) +2; //count how many leds you have connected + add 1 for all leds off
}
void loop ()
{
sensorValue = analogRead(sensorPin);
for (int num=0; num < 4; num++) {
sound[num]= analogRead (inputPIN);
if(num==3) {
soundav=(sound[0]+sound[1]+sound[2]+sound[3])/4; // average sound levels
x = map(soundav, 1, sensorValue, 0,leds);// map the sound values from 0 to 20 because we have 21 levels. OFF & 20 leds.
y = firstLED + x; //get the correct led pin number where the led state changes
for (int b= firstLED; b < y; b++) { //loops through all the leds from firstLED to the level of the sound
digitalWrite(b,HIGH);
}
for (int c = y; c <= lastLED ; c++) { //loops through all the leds from lastLED to the level of the sound
digitalWrite(c,LOW);
}
}
}
}
Esta programado de tal forma que se pueda modificar la sensibilidad de los leds con un potenciometro el unico problema es que cuando llega al maximo de leds encendidos ya sea por el volumen de entrada o modificando el valor de sensibilidad los leds se quedan todos encendidos y ya no hace nada. Al principio todo funciona bien lods leds van al ritmo pero como ya he dicho cuando llegan al maximo es como si el arduino dejara de leer y aunque modifique la sensibilidad con el potenciometro y la baje o baje el volumen no responde la unica solucion es darle a reset. Si alguien puediera ayudarme o tubiera otro codigo mejor estaria muy agradecido. Gracias un saludo
