The only thing I'd say it generally using Strings as arguments to setInterval/setTimeout is considered bad form in JS (and usually you'd just use functions like setTimeout(function() { ... }, 1000)), but honestly there's no good reason why it's bad on Espruino (Strings are actually faster) other than that you don't get the command syntax-highlighted/linted in the IDE.
What's a better set of arguments for the watch to detect, say, a press of between 50ms-100ms?
Ahh - yes, there's a trick to it :) If you detect the falling edge instead of the rising edge, then you're called when the button is released and you can compare how long it was held down for:
setWatch(function(e) {
var d = e.time - e.lastTime;
if (d>0.5/*seconds*/) console.log("Long press");
else console.log("Short press");
}, BTN, {repeat:true, edge:"falling", debounce:20});
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.
Thanks for posting it up - it looks good!
The only thing I'd say it generally using Strings as arguments to setInterval/setTimeout is considered bad form in JS (and usually you'd just use functions like
setTimeout(function() { ... }, 1000)
), but honestly there's no good reason why it's bad on Espruino (Strings are actually faster) other than that you don't get the command syntax-highlighted/linted in the IDE.Ahh - yes, there's a trick to it :) If you detect the falling edge instead of the rising edge, then you're called when the button is released and you can compare how long it was held down for: