You are reading a single comment by @mooniac and its replies. Click here to read the full conversation.
  • Not sure if I'm doing something wrong but code that previously worked when just applying power no longer works until I run the onInit manually (well it runs automatically on connect). Here is an example of code that used to work, meaning the onInit would be called and the code would operate properly:

    A5.write(0); // GND
    A7.write(1); // VCC
    
    var g;
    
    function onInit() {
      var spi = new SPI();
      spi.setup({ sck:B1, mosi:B10 });
      // Initialize the LCD
      g = require("PCD8544").connect(spi,B13,B14,B­15);
    }
    
    onInit();
    
    var sensor = require("HC-SR04").connect(A0,A1,functio­n(dist) {
      g.clear();
      g.setFontVector(10);
      g.drawString("Distance (cm)", 0, 0);
      var distance = "0"+dist;
      var start = Math.max((distance.indexOf('.')-4), 1);
      var end = distance.indexOf('.')+2;
      var d = distance.substr(start, end);
      g.drawString(d, (g.getWidth()-g.stringWidth(d)-14)/2, 15);
      g.flip();
    });
    
    setInterval(function() {
      sensor.trigger();
    }, 1000); 
    

    Any help is appreciated. Thanks!

About

Avatar for mooniac @mooniac started