You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi. It seems there's a bug in the interpreter that causes this to get reset...

    It must have crept in recently because that code did work when I wrote it. I've made an issue for it and I'll try and fix it today I hope: https://github.com/espruino/Espruino/iss­ues/233

    In the mean time, a simple change of order will help to fix it:

    Pin.prototype.startFlashing = function(period) {
      console.log(this);
      var pin = this;
      if (Pin.intervals===undefined) Pin.intervals = [];
      if (Pin.intervals[pin]) clearInterval(Pin.intervals[pin]);
      var on = false; 
      Pin.intervals[pin] = setInterval(function() {
        on = !on;
        digitalWrite(pin, on);
      }, period);
    };
    
About

Avatar for Gordon @Gordon started