Keypad - bought or DIY - controlled directly by Espruino #808
Replies: 5 comments
-
Posted at 2015-10-05 by @allObjects Sample output from KeypadMDS_Inline.js code (with AC control application in mind that toggles power and fan and 'ups' and 'down' temperature):
Noteworthy are lines with the negative numbers: Events in espruino are queued.... and with a lousy switch - I just used I wire to touch a Espruino Pico castellation pad which produced a lot of queud events... interestingly not on the touch, but on the 'move away' which then on scan did not show any buttons pressed. Therefore, Verified module usage with this code:
Producing this output:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-05 by @gfwilliams Looks great - just wondered though, how is this different to the existing http://www.espruino.com/KeyPad module? I think that does a very similar thing with pullups/watches. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-05 by @allObjects @gordon, ...just returning from looking at it for he first time... :( ... :[ ... 8{... LOL Intially, I had the feeling there must be already something because you listed a keypad under items with Espruino... but somehow did not look it up... and the problem kind of 'challenged' me. So my work was totally unbiased... may be because of the forum question and not finding a reference to the keypad module in your post there, I ventured into this exercise. Looking now at the existing moudule, it feels really like a programming excercise (like at a job interview)... but it was fun and is even more fun now to look at both and have 3rd thoughts (phase of 2nd thoughts have long gone). Conceptually I find the same things: array of driving pins and array of sensing pins, setting and clearing watches. Differences are:
Have to test and figure out behavior... used just wire to touch the castellation pads (have no keypad and was too lazy to wire up a DIY), and got flurry of events, which puzzled me, because I asked for 'repeat: false' in setWatch-option. Initially, in scan (readStatus in existing module), I wanted to use just the digitalWrite/Read with implicite output / input pinMod() setting on the driving pins, but it did not do what I wanted... may be I missed something or most likely got derailed by some other temporary issues the code had. Other than that, about the same... the available module looks a bit leaner due to function use and write/read of array. Both use set and clear watches... not much other way to do that. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-05 by @allObjects After having looked through both implementations side by side, I'm looking for some enhancement:
I'm thinking about a simple and lean for simple requirements, and dynamically extensible for more elaborate requirements. Minification may though defeat that in standard use. Minify and split up could be an option... or just have two modules with compatible simple interface. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-05 by @gfwilliams
That could be difficult - it was talked about in another thread on here, but unless you have diodes across each button it can get difficult to determine which button is pressed without 'ghosting'. But yes, I'm happy for you to submit a separate KeyPad module with extra features in it... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-10-05 by @allObjects
'After-completed-comment': Check out existing KeyPad.js module and its doc... and look at this conversation's code as a programming exercise... and a different style of doing things in JS...
Adding a human interfac / user interface is always a challenge. Below code provides you with function to drive and sense a matrix key pad with any nuber of rows and columns directly with Espruino. You need no other things than a passive - bought or DIY - key pad. For DIY, you need only push buttons and wire them in a matrix and let each button connect its row with its column wire when pressed. Then you connect the row and column wires to Espruino GPIO pins.
Schema of market available or DIY key pad with 12 keys (4 rows, 3 cols):
No additional components are needed: GPIO pins provide the built-in pull-up/down resistors to supprt the press detection and scanning.
Usage in your applicaiton is very simple - for example, for a 12-key pad driven with 4 row pins A0..3 and sensed with 3 column pins A4..6 (and default values for start enabled, watching falling edge, and 200[ms] debouncing):
Principle of operation is:
The code inlcudes some more functions to avoid overlapping and overruning events. It also includes two console log/debug statments in
.scan()
- lines 73 and 80 - to be removed for use in your project. Code is attached for easy download and use. Placed in 'project sandbox modules' folder (see Espruiono IDE setings), it can be pulled as KeypadMDS module withrequire("KeypadMDS")
.Fedback is welcome. 'Exercise' was triggered by - paraphrased - How can I do some Arduino(-like) loop to monitor my hardware events... (see conversation).
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions