I want to light an LED in a sketch and then have it fade out. I tried to use analogWrite and have it decrease from a value of 255 to 0 using a for() loop, but I can't seem to get it to work. Using digitalWrite I can turn it on and off but cant get it to fade out. Can anyone help please.
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 9;
int j = 0;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop() {
j = 255;
delay(1000);
if (j >= 5);
{
analogWrite(ledPin3,j);
delay(10);
j = j - 5;
}
delay(1000);
}