You are reading a single comment by @HaraldK and its replies. Click here to read the full conversation.
  • Ok, I officially am a JS noob...thanks for the explanation. At first I did not see the difference, but I saw what to check.
    I kind'a get it now and this helped:

    var glow=function(led, stp) {
      var intensity=0;
      var dir=1.0;
      var this_led=led;
      var this_stp=stp;
      function intensity_step() {
        intensity+=dir*this_stp;
        if (intensity>=1.0) {
          intensity=1.0;
          dir=-dir;
        }
        if (intensity<=0.0) {
          intensity=0;
          dir=-dir;
        }
        analogWrite(this_led, intensity);
      }
      return intensity_step;
    };
    
    var led1=glow(D13,0.01);
    setInterval(led1, 2);
    

    Is that behavior a generic JS thing or the implementation of setInterval()?

About

Avatar for HaraldK @HaraldK started