Tessel Async Matrix Keypad
This library will allow your Tessel to read any matrix type keypad. This was created specifically for Tessel 2 but may also work on Tessel 1. This was branched from Nathan White's work because the Tessel 2 doesn't have a synchronous pin read.
About Matrix Keyboards
A really good write up on how key matrices work
The arduino matrix keypad how-to provides inspiration for this library.
npm install tessel-async-matrix-keypad --save
var tessel =Keypad =keypadPins = tesselportApin; //shortcut for referencing Tessel pinsvar keypad =keys:'1' '2' '3' 'A''4' '5' '6' 'B''7' '8' '9' 'C''*' '0' '#' 'D'rows: keypadPins0 keypadPins1 keypadPins2 keypadPins3cols: keypadPins4 keypadPins5 keypadPins6 keypadPins7scan: 'row' // 'col' or 'both'poll: false // number sets for auto polling (integer);keypad;keypad;keypad;
Create keypad instance
var Keypad = ;var keypad = options;
keys: array of keys by row ex: [[1,2,3],[4,5,6],[7,8,9]] required
rows: array of digital pins on tessel associated with rows required
cols: array of digital pins on tessel associated with cols required
scan: direction to scan the keys default:
row: row pins are pulled high to correspond with columns.
col: column pins are pulled high to correspond with row pins.
both: both rows and column are scanned. This helps to solve for ghosting with multiple keys. It is also slower.
poll: how often to poll for key updates in ms. Relative to last poll. default:
isPressed(key), isPressed(row, col, callback(err, value))
Checks to see if key(s) are pressed. Valid argument is a string separated by spaces.
Executes callback that is passed in with err and value parameters. The value parameter will contain a boolean.
In the example above the key
A must be pressed for value to be true.
Check to see if the key at row 0, col 0 is pressed. If the key at row 0, col 0 is pressed, value will be true.
Executes callback when finished. The err parameter will contain any errors. The value parameter will contain an array of currently pressed keys.
Stops polling the keypad for events.
Starts polling the keypad.
Index the keys. Allows for reassignment of the keys on a keypad instance. This will reset all key states to false.
Reset the all key states to false. Uses the existing key layout.
Allows changing the polling of the keyboard.
Changes how the matrix is scanned. See options for valid arguments (
Emitted when a key is pressed and was previously not pressed. The key value is passed to the listener.
Emitted when a key that was pressed in a prior polling is no longer pressed. The key value is passed to the listener.
Anytime a key state changes
change is emitted with two arguments.
key: the key that has changed state.
type: a boolean indicating the new state.
When polling is stopped this is emitted.
The MIT License (MIT)
Copyright (c) 2014 Nathan White
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.