Debouncing issues with setWatch();

Posted on
  • Firmware 1v79

    I have a noisy button on B5.

    The default debounce setting (10ms) per setWatch() docs doesn't seem to do anything. When I add debounce: 20 (or any value), it prevents the callback from getting any args. Code below.

    Recommendations?

    var button=B5;
    pinMode(button, 'input_pulldown');
    function buttonPressed(info) {
            console.log(info);  // [ undefined ]
            info.time;   // Uncaught Error: Field or method "time" does not already exist, and can't create it on undefined
    }
    setWatch(buttonPressed,button,
             {repeat:true,debounce:200});
    
    
  • Interesting - thanks. That looks like a regression - I'll create a bug for it and will see if I can get it done for the next release.

    When you're using debounce you're not going to get a very accurate time anyway though given all the bouncing. In this case, why not just use the getTime() function?

    Granted getting button state is more of a pain, but the best bet for now is just to use digitalRead(button) as the watch will only have been called if the button state has been stable for a while.

  • .

  • .

  • Fixed now, it'll be in the 1v80 release. Available from http://www.espruino.com/binaries/git/com­mits/03bc4de4ed9fee0a7863c0e55040ad79f2a­2fa35 in a few minutes

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Debouncing issues with setWatch();

Posted by Avatar for RandyHarmon @RandyHarmon

Actions