Hey Im trying to make somewhat of a VU meter. This code is ok but I would like to have a feeling of it responding to the intensity of the sound instead of just always cycling through the full array of LEDs. I am not a very experienced programmer so any help or amendments to this code would be much appreciated.
Cheers
int timer = 50; // The higher the number, theslower the timing.
int pins[] = {2, 3, 4, 5}; // an array of pin numbers
int num_pins = 4; // the number of pins (i.e. the length of the array)
int inPin = 12;
int val = 0;
void setup()
{
Serial.begin(9600);
pinMode (inPin, INPUT); //sets the digital pin 10 to input
digitalWrite (inPin, HIGH);
int i;
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output
}
void loop()
{
val = digitalRead(inPin);
Serial.print(val);
int i;
if(val == LOW) {
for (i = 0; i < num_pins; i++) { // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
delay(timer); // pausing,
//digitalWrite(pins[i], LOW); // and turning it off.
}
}
if(val == HIGH) {
for (i = num_pins - 1; i >= 0; i--) {
// digitalWrite(pins[i], HIGH);
digitalWrite(pins[i], LOW);
delay(timer);
}
}
}