Didn't manage to make the LED fade.?

I followed a lesson on YouTube by Paul McWhorter and managed to write the following

int LEDPin=9;

int waitTimeOn=50;

int waitTimeOff=350;

void setup () {

pinMode(LEDPin,OUTPUT);

}

void loop() {

digitalWrite(LEDPin,HIGH);

delay(waitTimeOn);

digitalWrite(LEDPin,LOW);

delay(waitTimeOff);

}

Of course I played around with the wait times but I was never able to make the LED actually fade in and out. What did I do wrong? Thank you for your help.


randofo8 months ago

You are setting the LED high and low (on and off) with digital write. You need to use analogWrite in the loop and give it values between 0 and 255. I recommend looking at the Fade example in the Arduino software. Also, you may want to check out the Arduino Class:

https://www.instructables.com/class/Arduino-Class/