Ic. Good practice is to put the actions into an onInit() function. To get it going on development time, you add a delayed invocation of it, like this:
var hat = require('servo').connect(A0);
var pos=0,t=null;
function sweep(){
hat.move(pos,500,function(){
if(pos===0){pos=1;}else{pos=0;}
t=setTimeout(function(){ sweep(); },1000);
});
}
function onInt() {
hat.move(0.5, 1000, sweep)
}
// for convenience while developing:
setTimeout(onInit, 1000);
Adding the last line simulates a power on with saved code, and you do not have to enter that in the console every time after upload. When you are done with development, the last line is removed just before saving the code.
That of course does not solve the positioning issue...
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.
Ic. Good practice is to put the actions into an
onInit()
function. To get it going on development time, you add a delayed invocation of it, like this:Adding the last line simulates a power on with saved code, and you do not have to enter that in the console every time after upload. When you are done with development, the last line is removed just before saving the code.
That of course does not solve the positioning issue...