-
• #2
You could just copy the code right into your main code? So change:
exports.connect = function (columns, rows, callback) {
to:
var keypad_connect = function (columns, rows, callback) {
and then use
keypad_connect(...)
instead ofrequire("KeyPad")
- hope that helps! -
• #3
Thanks for the reply @Gordon. Sorry I wasn't clear, I tried to do that but I couldn't understand the keypad.js enough to successfully modify it for ESP8266. I tried to switch all the "input_pulldown" to "input_pullup" and set the rows to low instead of high but no dice. Any hint on how to accomplish this in general? Thanks again!
PS. Kudos & great work with Espruino! made MCU development so accessible to an old JS hack like me :) I bought all 3 variants of the official espruino board, but planning to use NodeMCU boards as "throwaway" project boards.
-
• #4
Wow, thanks!
Ahh, ok - yes, I'm pretty sure it is possible. What about this:
function (columns, rows, callback) { var watches = []; var lastState = 0; var readState = function() { var press = -1; for (var i in rows) { digitalWrite(rows, 0xFFFFFFFF ^ (1 << i)); var v = digitalRead(columns); for (var j in columns) if (!(v & (1<<j))) press = j+i*columns.length; } // reset state digitalWrite(rows, 0); return press; }; var setup = function() { for (var i in columns) pinMode(columns[i], "input_pullup"); digitalWrite(rows, 0); }; var onWatch = function() { var s = digitalRead(columns); if (s!=lastState) { lastState = s; removeWatches(); var c = readState(); addWatches(); if (c>=0) callback(c); } }; var addWatches = function() { for (var i in columns) watches[i] = setWatch(onWatch, columns[i], { repeat:true, edge:"both" }); }; var removeWatches = function() { for (var i in watches) clearWatch(watches[i]); }; setup(); if (callback!==undefined) addWatches(); return { read: readState }; };
I haven't tried it but I think it's ok - basically I had to invert everything, any time a pin was written or read.
-
• #5
That works perfect!! Thanks, you're the best!
Has anyone ever successfully used a 4x4 switch matrix on ESP8266? Since ESP8266 doesn't support "input_pulldown" on its pins in Espruino, the module from http://www.espruino.com/modules/KeyPad.js doesn't work. Is it possible to modify that module to use "input_pullup" instead?