Ok so I got a bit further but am having trouble combing the 3 codes, any help?
To fade an LED
int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9
void setup()
{
// nothing for setup
}
void loop()
{
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
delay(30); // waits for 30 milli seconds to see the dimming effect
}
for(value = 255; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(ledpin, value);
delay(30);
}
}
To cycle LED in an array
int timer = 100; // The higher the number, the slower the timing.
int pins[] = { 2, 3, 4, 5, 6, 7 }; // an array of pin numbers
int num_pins = 6; // the number of pins (i.e. the length of the array)
void setup()
{
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()
{
int i;
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.
}
for (i = num_pins - 1; i >= 0; i--) {
digitalWrite(pins[i], HIGH);
delay(timer);
digitalWrite(pins[i], LOW);
}
}
To control the VU meter (as a seperate function)
byte voltageReferencePin = 0;
byte voltagePin = 2;
byte ledPins[6] = { 8 , 9 , 10 , 11 , 12 , 13 };
byte voltageComparisonThresholds[] = { 0 , 10 , 30 , 55 , 80 , 100 };
int voltageReference = 0; //contain analogRead(voltageReferencePin);
int samples[NUMBER_OF_SAMPLES] = {0};
int sample = 0;
int sampleTotal = 0;
byte sampleIndex = 0;
void setup() {
for (byte i=0; i<NUMBER_OF_LEDS; i++){
pinMode(ledPins[i],OUTPUT);
}
pinMode(voltageReferencePin,INPUT);
pinMode(voltagePin,INPUT);
if(DEBUG){Serial.begin(9600);}
}
void loop(){
sampleTotal -= samples[sampleIndex];
samples[sampleIndex] = analogRead(voltageReferencePin);//read value
sampleTotal += samples[sampleIndex++];
if (sampleIndex >= NUMBER_OF_SAMPLES) {sampleIndex = 0;}
sample = sampleTotal / NUMBER_OF_SAMPLES;
if(DEBUG){Serial.print("virtual vu: ");}
for (byte i=0; i<NUMBER_OF_LEDS; i++){
if ( analogRead(voltagePin) >= voltageReference + voltageComparisonThresholds[i] ) {
digitalWrite(ledPins[i],HIGH); if(DEBUG){Serial.print("|");}
}else{
digitalWrite(ledPins[i],LOW); if(DEBUG){Serial.print(" ");}
}
delay(VU_METER_DISPLAY_DELAY);
}
if(DEBUG){ Serial.println(" "); }
}