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,B15);
}
onInit();
var sensor = require("HC-SR04").connect(A0,A1,function(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);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
Any help is appreciated. Thanks!