digitalWrite(led[randnum], LOW);* } randomly in this case. Now i wonder how can i fade all led together? Must not be randomly for example. By the way i wonder why all led stay a little amount on in the function above. They only turn real off, since i added the "digitalWrite(led[randnum], LOW);" line ? THX for your reply`s Matthias
Do not mix analog output functions and digital output functions. If you do an analogWrite with a value of 0 the led should be off, there is no need for a digitalWrite to set this pin off!
thx for the quick answer I had an anticipation the solution must be easy. But my way of solving the problem has turned in the wrong direction..
Now I changed the power value (in the fade out) to 0 and commented out the "digitalWrite(led[randnum], LOW);" line temporarily.
The problem stays the same. The led s didn't turn realy off. They shine like pwm value 20 until the other randomly selected led is working.
void ledDrive () { //twinkle effect
int randnum = random(0, 6); //led nr
int randnum1 = random(0, 254); //power
int randnum2 = random(5, 100); //delay
Serial.print("led nummer");
Serial.println(randnum);
//fade in
for (int power=0; power<randnum1; power++) {
analogWrite(led[randnum], power); //Serial.println(power);
delay(randnum2);
}
//fade out
for (int power=randnum1; power>0; power--) {
analogWrite(led[randnum], power); //Serial.println(power);
delay(randnum2);
}
//digitalWrite(led[randnum], LOW);
}