• I ended up wanting to do something like this too. I actually ended flashing with a sin wave instead to simplify things and it gives it a nice glow IMO. You can change how long the flash cycle is by adjusting the constant to multiply getTime() by. I liked a 2 second cycle, hence the code below.

    To ensure it always starts by fading in you could use a new Date object when you start the fade instead.

    function fadeLED() {
      analogWrite(ledPin, (Math.sin(getTime()*3)+1)/2);
    }
    
    setInterval(fadeLED, 10);
    
About

Avatar for user152410 @user152410 started