For the KeyPad module, there's a cunning(ish) way of handling KeyPads that doesn't involve scanning them all the time: http://www.espruino.com/modules/KeyPad.js
Basically you put all the columns into 'pulldown' state and watch them, then set all the rows to 1.
So then you can just wait until the pins change state, and then do a proper scan to see what was pressed, then go back to watching the pins again.
If you're only planning on handling one press at a time then you can just do the whole thing like that, since the state of the pins will change whenever a button is pressed or released.
If you want to try and handle > 1 press (which isn't always guaranteed on a matrix keypad) then you'll have to keep scanning while a button is held, but even that isn't such a big deal as I imagine the buttons won't stay pressed for too long?
© Espruino, powered by microcosm.
Report a problem