Hey guys,
I’m sure I’m missing something pretty basic, but I can’t seem, for the life of me, to use digitalRead and digitalWrite in my node.js program.
I’m on a Raspberry Pi B+, and things are working fine in general (I can pass virtual values around, I’ve hard-wired a button to a GPIO pin and it works etc).
Thing is, I’d like to send a message to my LCD widget (via virtualWrite) once a digital pin goes high. I thought I’d use digitalRead for this, but I’m failing miserably. Here are the pertinent parts of my code:
#!/usr/bin/env node
var Blynk = require('/usr/local/lib/node_modules/blynk-library');
// various init stuff cut from here
//V0 is tied to the LCD (simple mode) with refresh 1sec
v0.on('read', function(param) {
blynk.virtualWrite(1,LCDLine1);
blynk.virtualWrite(2,LCDLine2);
var check = digitalRead(2);
});
When run, this fails with the following message:
/home/pi/blynk/homeControl.js:43
var check = digitalRead(2);
^
ReferenceError: digitalRead is not defined
at null.<anonymous> (/home/pi/blynk/homeControl.js:43:14)
at emit (events.js:104:17)
at Blynk.onReceive (/usr/local/lib/node_modules/blynk-library/blynk.js:466:27)
at null.<anonymous> (/usr/local/lib/node_modules/blynk-library/blynk.js:532:50)
at emit (events.js:107:17)
at Socket.<anonymous> (/usr/local/lib/node_modules/blynk-library/blynk-node.js:50:14)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
I’ve tried all the permutations I could think of, like digitalRead(“2”), digitalRead(“D2”), blynk.digitalRead(2) etc…
I’m obviously missing something. What?