Code needed to discard multiple physical and logical press events within the debounce time: happening while pressing temp down and temp up the first time (tp < np, a negative value, this_press_time < nextallowedpress time) - in lines 11. and 25.
Scanning is optimized - and simplified - and so the result: 'first' (lowest) detected pressed button (number) is used. If multi-pressings are not (yet) detected.
Enhancements to think about are:
detection of multiple button presses and optionally allow / disallow
press and hold button
provide press (button down) and release (button up) information in either same or
separate callbacks.
press-'fumblin' (timely overlapping of presses of multiple/different buttons
You can use any number of driving and sensing pins. Using Espruino directly - driving and sensing pins each using a GPIO pin - is 'expensive'. Using some SPI or I2C driven port yields more pins for other things... but requires this extra chip and wiring...
Was a fun exercise - with some serious challenges as every HI / input (and output) UI has.
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.
Verified (and enhanced) code creates this console output:
Noteworthy:
Code needed to discard multiple physical and logical press events within the debounce time: happening while pressing temp down and temp up the first time (tp < np, a negative value, this_press_time < nextallowedpress time) - in lines 11. and 25.
Scanning is optimized - and simplified - and so the result: 'first' (lowest) detected pressed button (number) is used. If multi-pressings are not (yet) detected.
Enhancements to think about are:
separate callbacks.
You can use any number of driving and sensing pins. Using Espruino directly - driving and sensing pins each using a GPIO pin - is 'expensive'. Using some SPI or I2C driven port yields more pins for other things... but requires this extra chip and wiring...
Was a fun exercise - with some serious challenges as every HI / input (and output) UI has.
Useful for marketed and DIY matrix key pads.
Practically module-ready...