Nice solution, Bogdan. I would improve it to allow passing params from one to another, so you would not need to use globals. This does degrade readability though:
function setupBTN1(customParams) {
return function() {
function test() {
return callback();
}
var id = setWatch(test, BTN1, {repeat:false, edge:"rising"});
function callback() {
console.log('Hello! watch id was', id, 'and customParams was', customParams);
clearWatch(id);
setTimeout(setupBTN1(customParams + Math.random()), 1000);
}
};
}
setupBTN1(0)();
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.
Nice solution, Bogdan. I would improve it to allow passing params from one to another, so you would not need to use globals. This does degrade readability though: