• Could anyone help to solve an issue with my code?
    I have 3 screens, first screen "one" on the beginning, then second screen "OLED OFF?" and third "analogRead(A5)"
    until I change screens by button (setWatch) and have no intervals set then it works really well, no lags, but when I want to update this analogRead(A5) informations every 500ms then I noticed that I can't switch to the other screen just by one push of the button, sometimes I need several or dozen push to do it, when I don't use intervals it works again,
    what should I change to be able to have few screens where I can watch on different analog values updated every 500-1000ms?

    
    
    function OLED(){
    clearWatch();
    
    I2C1.setup({scl:B6,sda:B7});
    var g = require("SSD1306").connect(I2C1);
    g.clear();
      g.flip();
      
    pinMode(B14, 'input_pulldown');
    
    var BTN22 = B15;
    var screen = 0;
    var battery = analogRead(A5)*2*3.3;
    
    function screens(){
      g.clear();
      g.setFontVector(15);
      g.drawString("one",25,20);
      g.flip();
    }
    
    function screens2(){
     g.clear();
     g.setFontVector(15);
     g.drawString("OLED OFF?");g.flip();
    }
    
    function screens3(){
      battery = analogRead(A5);
     g.clear();
     g.setFontVector(20);
     g.drawString("" + battery.toFixed(2),20,20);
     g.flip();
    }
    
    
    setWatch(function(e) {
      clearInterval();
        screen++;
        console.log(screen);
        if(screen === 0) screens();
      if(screen === 1) screens2();
      if(screen === 2) screens3();setIterval(screens3,500);
      if(screen >= 2) screen = 0;
    },BTN22, {repeat: true, edge: 'rising', debounce:150});
    
               
    OLED();
    
About

Avatar for bigplik @bigplik started