Introductory Keypad support has landed in Johnny-Five! The new Keypad
class makes adding an analog or I2C keypad component to your project as simple as:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// This will initialize a SparkFun VKEY Keypad
var keypad = new five.Keypad({
controller: "VKEY",
pin: "A0",
});
keypad.on("press", function(data) {
console.log("Pressed: ", data.which);
});
});
Programs can optionally specify special characters for keypad keys to represent:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// This will initialize a SparkFun MPR121QR2 Capacitive Touch Keypad
var keypad = new five.Keypad({
controller: "MPR121QR2",
keys: [
["!", "@", "#"],
["$", "%", "^"],
["&", "-", "+"],
]
});
keypad.on("press", function(data) {
console.log("Pressed: ", data.which);
});
});
Take a look at these examples:
The new Keypad
class has been in the pipeline for many months as we tried to figure out how to support keypad components that require many pins and synchronous, explicit order write-read-write operations. Current support only covers keypad components that interact via ADC or I2C. For digital keypads, ie. electro-mechanical, or membrane devices, the path forward is to develop an "I2C backpack" approach that can be easily reproduced. This approach is how Andrew Fisher added support for NeoPixels and an alternative Ultrasonic Ping implementation.
Please report any issues here.