You are right, I was unnecessarily complicating things. Thanks a lot for your suggestion @DrAzzy
This is what I have got now
let ledBrightness = 0; let ledPin = D15; let fadeIn = false; function fadeLED() { if((ledBrightness <= 0) || (ledBrightness >= 1)){ fadeIn = !fadeIn; } setLedBrightness(fadeIn); } function setLedBrightness(fadeIn){ if(fadeIn){ ledBrightness += 0.01; } else { ledBrightness -=0.01; } analogWrite(ledPin, ledBrightness); } setInterval(fadeLED , 10);
@Chaapu started
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.
You are right, I was unnecessarily complicating things. Thanks a lot for your suggestion @DrAzzy
This is what I have got now