I'm new to nodejs, and what I did was, I connected the LCD panel and 4x4 Membrane matrix keyboard to the Raspberry Pi, and I programmed them using Node.js. What I want to achieve is that whenever a key is pressed, it should be displayed immediately on the LCD panel, and when I press #, it should stop accepting input.
For this, I used the LCD packages https://www.npmjs.com/package/lcd and RPIO https://github.com/jperkin/node-rpio , and since I have to constantly check user input, I put the code for input during the cycle and inside that I wrote the print instruction, and that is where the problem goes. The LCD panel does not display a character when I press a key on the keyboard, but when I press #, the program exits and all the characters are displayed on the LCD panel.
The code I wrote is as follows.
var rpio = require('rpio'); var Lcd = require('lcd'),//This is asynchronous function lcd = new Lcd({ rs: 18, e: 23, data: [24, 17, 27, 22], cols: 8, rows: 2 }); var matrix=[[1,2,3,'A'], [4,5,6,'B'], [7,8,9,'C'], ['*',0,'#','D']] var row=[37,35,33,31]; var col=[29,23,40,38]; for (var i = 0; i < 4; i++) { rpio.open(col[i], rpio.OUTPUT, rpio.HIGH); } for (var i = 0; i < 4; i++) { rpio.open(row[i], rpio.INPUT, rpio.PULL_UP); } var code=""; var comeout=0; lcd.on('ready', function() { lcd.setCursor(0, 0); //start of keypad code while(true){ for (var j = 0; j < 4; j++) { rpio.write(col[j],rpio.LOW); for (var i = 0; i < 4; i++) { if(rpio.read(row[i])==0){ console.log(matrix[i][j]); lcd.print(matrix[i][j]); if(matrix[i][j]=='#'){ comeout=1; break; } while(rpio.read(row[i])==0); } } if(comeout==1) break; else rpio.write(col[j],rpio.HIGH); } if(comeout==1) break; } //end of keypad code }); // If ctrl+c is hit, free resources and exit. process.on('SIGINT', function() { lcd.clear(); lcd.close(); process.exit(); });
Any help would be greatly appreciated. Thanks.