tessel-async-matrix-keypad

1.0.1 • Public • Published

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

Matrix Keypad Diagram

You can purchase such keypads here, here or here.

A really good write up on how key matrices work

The arduino matrix keypad how-to provides inspiration for this library.

Install

  npm install tessel-async-matrix-keypad --save

Usage

  var tessel = require('tessel')
    , Keypad = require('tessel-async-matrix-keypad')
    , keypadPins = tessel.port.A.pin; //shortcut for referencing Tessel pins

  var keypad = new Keypad({
    keys: [
      ['1', '2', '3', 'A'],
      ['4', '5', '6', 'B'],
      ['7', '8', '9', 'C'],
      ['*', '0', '#', 'D']]
  , rows: [keypadPins[0], keypadPins[1], keypadPins[2], keypadPins[3]]
  , cols: [keypadPins[4], keypadPins[5], keypadPins[6], keypadPins[7]]
  , scan: 'row' // 'col' or 'both'
  , poll: false // number sets for auto polling (integer)
  });

  keypad.on('change', function(key, val){

  });

  keypad.on('keydown', function(key){

  });

  keypad.on('keyup', function(key){

  });

Create keypad instance

var Keypad = require('tessel-async-matrix-keypad');

var keypad = new Keypad(options);

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: 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: false

API methods

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.

  keypad.isPressed('1 4 A', callback(err, value));

In the example above the key 1, 4 and A must be pressed for value to be true.

Alternative usage:

  keypad.isPressed(0, 0, callback(err, value));

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.

getPressed(callback(err, value))

Executes callback when finished. The err parameter will contain any errors. The value parameter will contain an array of currently pressed keys.

stop

Stops polling the keypad for events.

start

Starts polling the keypad.

index(layout)

Index the keys. Allows for reassignment of the keys on a keypad instance. This will reset all key states to false.

reset

Reset the all key states to false. Uses the existing key layout.

poll(ms)

Allows changing the polling of the keyboard.

scan(type)

Changes how the matrix is scanned. See options for valid arguments (row, col, both)

Events

keydown

Emitted when a key is pressed and was previously not pressed. The key value is passed to the listener.

keyup

Emitted when a key that was pressed in a prior polling is no longer pressed. The key value is passed to the listener.

change

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. true = pressed, false = notpressed

stop

When polling is stopped this is emitted.

License

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.

Readme

Keywords

none

Package Sidebar

Install

npm i tessel-async-matrix-keypad

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • bmccord