@allObjects is likely spot on - it'd be interesting to see if just removing the LED fixes it.
But just to add to this, if you have an input that really does fluctuate a massive amount, debounce and repeat:false probably won't help you much since by the time they take effect the event queue could be full of events already.
It's not at nice, but you could just 'poll' the input:
var n=0;
function poll() {
var newn = E.clip(n+digitalRead(...)-0.5,-20,20);
if (newn==-20 && n!=-20) ...;
if (newn==20 && n!=20) ...;
n = newn;
}
setInterval(poll,5);
Although the best solution is to try and 'clean up' the input. In your case you could add hysteresis by putting a high value resistor from the output of the comparator back into one of the two inputs (doing it to one will make it oscillate even more, the other should really sort it out).
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.
@allObjects is likely spot on - it'd be interesting to see if just removing the LED fixes it.
But just to add to this, if you have an input that really does fluctuate a massive amount,
debounce
andrepeat:false
probably won't help you much since by the time they take effect the event queue could be full of events already.It's not at nice, but you could just 'poll' the input:
Although the best solution is to try and 'clean up' the input. In your case you could add hysteresis by putting a high value resistor from the output of the comparator back into one of the two inputs (doing it to one will make it oscillate even more, the other should really sort it out).