Hi, I'm pretty new to Arduino and the coding. I'm working on LED-fading and I'm using the code from the basic example. I noticed that the loop repeats itself a bit too fast once it reach 0 brightness. I'm wondering what kind of code I have to add to make the LED stay longer off. I want to make a more smooth loop.

Really thankful for any answer.

Hey you could show us what you have done ( put the code in code tags) , but you could just add


Or you can look at the blink without delay example in your ide and use that.


Edit: Sorry didnt read that u using the standard example , so just increase your delay so that the loop takes longer to go to the next loop so with other words your dimming will slow down.

Thank you for your answer! I’m using a delay of (45) at the moment and will be using something like that, but once the loop goes back from 255 to 0 brightness it goes up again quite fast without any pause. I’d like to make it stay at 0 brightness for a short duration before going up to 255 brightness.

I’ll add the code (Basically the same as the one from the example).

fade_arduino_basic.ino (313 Bytes)

Ok the you can add this :

if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 

This will then give a short delay when the led is fully on or fully off you can adjust that to suit your needs.