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);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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.