• Ahh - I just tried this, and it does appear to be a bug in Espruino.

    I believe it happens when you use clearInterval() (with no arguments) and debounce in a watch, as debounced watches use setTimeout behind the scenes. I'll get a fix in for this.

    In the mean time, you can work around it by only clearing the interval you want:

    // ...
    var intr;
    function interval(){
      intr = setInterval(read,500);
    }
    function interval2(){
      intr = setInterval(read2,500);
    }
    function display(){
      if(screen === 1)interval();
      if(screen === 0)interval2();
      //console.log(screen);
    }
    
    setTimeout(function(){
      display();
    },2000);
    
    setWatch(function(e) {
      if (intr) clearInterval(intr);
      intr = undefined;
    
      display();
      console.log(screen);
      screen = screen + 1;
      if(screen > 1) screen = 0;
    }, BTN1, {repeat: true, edge: 'rising', debounce:50});
    
About

Avatar for Gordon @Gordon started