You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Tried to look at your uploaded compete code 'Fermentadora'... but don't kow how to look at it.

    I though did lookup the SSD1306 module and I found that the .connect(...) accepts a callback function as second argument... and when using this callback to call your code that has to be executed afterwards, it should time just right! (The module does internally already a lot of setTimeout(...) to manage timing... for you... when using the callback. If it still does not work, the times used in these setTimeout(...) should be adjusted in the module.)

    PS: ...could it be that start in connect should be something like the Start_read()?

    Without knowing all the details, I would give this restructured code a shot:

    var dht, i2c, g;
    function initializeall() {
      pinMode(B15,'input_pullup');
      pinMode(B14,'input_pullup');
      pinMode(B13,'input_pullup');
      dht = require("DHT22").connect(B5);
      require("Font6x8").add(Graphics);
      require("Font8x16").add(Graphics);
      i2c = new I2C();
      i2c.setup({ scl : B6, sda: B7, bitrate: 1000000  });
      g = require("SSD1306").connect(i2c, start, { height : 32 });
    }
    
    function start() {
      setWatch(selection, B15, { repeat: true, edge:'falling', debounce:20});
      setWatch(BtnUP    , B14, { repeat: true, edge:'falling', debounce:20});
      setWatch(BtnDown  , B13, { repeat: true, edge:'falling', debounce:20});
      Start_read();
    }
    
    // .....
    
    function onInit() {
      USB.setConsole(true);
      setTimeout(function () {
                    initializeall();
                    }, 
          1000);
    }
    
About

Avatar for allObjects @allObjects started