3 PWM

hello! i’m working on a interactive wall and i need to use a big number of leds an lightresensors. I started puttin g the leds in the 9 10 11 pin (PWM) and i controlled them with lightsensor on digital pins…
here’s my code…

int ledPinC = 11;
int inPinC = 8;
int valueC = 0;
int valC = 0;

int ledPinB = 10;
int inPinB = 7;
int valueB = 0;
int valB = 0;

int ledPinA = 9;
int inPinA = 6;
int valueA = 0;
int valA = 0;

void setup() {
pinMode(ledPinC, OUTPUT); // declare LED as output
pinMode(inPinC, INPUT); // declare pushbutton as input

pinMode(ledPinB, OUTPUT); // declare LED as output
pinMode(inPinB, INPUT); // declare pushbutton as input

pinMode(ledPinA, OUTPUT); // declare LED as output
pinMode(inPinA, INPUT); // declare pushbutton as input
}

void loop(){

valC = digitalRead(inPinC); // read input value

if (valC == LOW) {
digitalWrite(ledPinC, LOW); // turn LED OFF
}

if (valC == HIGH) {
for(valueC = 0 ; valueC <= 255; valueC+=5) // fade in (from min to max)
{
analogWrite(ledPinC, valueC); // sets the value (range from 0 to 255)
delay(15); // waits for 30 milli seconds to see the dimming effect
}
for(valueC = 255; valueC >=0; valueC-=5) // fade out (from max to min)
{
analogWrite(ledPinC, valueC);
delay(15);
}
}

valB = digitalRead(inPinB); // read input value

if (valB == LOW) {
digitalWrite(ledPinB, LOW); // turn LED OFF
}

if (valB == HIGH) {
for(valueB = 0 ; valueB <= 255; valueB+=5) // fade in (from min to max)
{
analogWrite(ledPinB, valueB); // sets the value (range from 0 to 255)
delay(15); // waits for 30 milli seconds to see the dimming effect
}
for(valueB = 255; valueB >=0; valueB-=5) // fade out (from max to min)
{
analogWrite(ledPinB, valueB);
delay(15);
}
}

valA = digitalRead(inPinA); // read input value

if (valA == LOW) {
digitalWrite(ledPinA, LOW); // turn LED OFF
}

if (valA == HIGH) {
for(valueA = 0 ; valueA <= 255; valueA+=5) // fade in (from min to max)
{
analogWrite(ledPinA, valueA); // sets the value (range from 0 to 255)
delay(15); // waits for 30 milli seconds to see the dimming effect
}
for(valueA = 255; valueA >=0; valueA-=5) // fade out (from max to min)
{
analogWrite(ledPinA, valueA);
delay(15);
}
}

}

NOW: MY QUESTION IS: HOW CAN I MAKE THE LEDS FADE ALL TOGHETER (IF THE 3 LIGHTSENSORS ARE LOW, FOR EXAMPLE)? WITH MY SCRIPT THE LEDS FADE IN AND OUT ONCE AT TIME… BUT NOTHING APPENS DURING A LOOP FADE IN-OUT…

sorry for my bad english… i’m a poor stupid student… and i’m italian… so…

Why don't you put it all in 1 loop? You can control all 3 leds with 1 variable.

i've done... in another way... but i've done... this is the right code.. it works perfectly!!! :D:D:D

int ledPinC = 11; int inPinC = 4; int valueC = 0; int valC = 0; int incrementoC = 0;

int ledPinB = 10; int inPinB = 3; int valueB = 0; int valB = 0; int incrementoB = 0;

int ledPinA = 9; int inPinA = 2; int valueA = 0; int valA = 0; int incrementoA = 0;

void setup() { pinMode(ledPinC, OUTPUT); pinMode(inPinC, INPUT);

pinMode(ledPinB, OUTPUT); pinMode(inPinB, INPUT);

pinMode(ledPinA, OUTPUT); pinMode(inPinA, INPUT);

}

void loop(){ gestioneSensoriLuminosi(); delay( 15 ); }

void gestioneSensoriLuminosi() { valC = digitalRead(inPinC); valB = digitalRead(inPinB); valA = digitalRead(inPinA);

if ( ( valC == LOW ) && ( valueC == 0 ) ) { digitalWrite(ledPinC, LOW); }else { valueC = valueC + incrementoC;

analogWrite( ledPinC, valueC );

if ( valueC == 255 ) { incrementoC = -5; }

if ( valueC == 0 ) { incrementoC = +5; } }

if ( ( valB == LOW ) && ( valueB == 0 ) ) { digitalWrite( ledPinB, LOW ); }else { valueB = valueB + incrementoB;

analogWrite( ledPinB, valueB );

if ( valueB == 255 ) { incrementoB = -5; }

if ( valueB == 0 ) { incrementoB = +5; } }

if ( ( valA == LOW ) && ( valueA == 0 ) ) { digitalWrite( ledPinA, LOW ); }else { valueA = valueA + incrementoA;

analogWrite( ledPinA, valueA );

if ( valueA == 255 ) { incrementoA = -5; }

if ( valueA == 0 ) { incrementoA = +5; } } }