Simple wrapper for the PiFace Digital and NodeJS (v4+ or v5+)
Note: recent Kernel versions need Device-Tree to be disabled in order to use SPI.
Follow the instructions available here: https://nodejs.org/en/download/package-manager/
(Optional) Update npm
and node-gyp
npm install -g npm@latest
npm install -g node-gyp@latest
sudo apt-get install automake libtool git
git clone https://github.com/thomasmacpherson/piface.git
cd piface/c
./autogen.sh && ./configure && make && sudo make install
sudo ldconfig
cd ../scripts
sudo ./spidev-setup
npm install piface
var pfio = require("piface");
pfio.init();
var i = 0;
for (i = 0; i < 8; i++) {
console.log("Pin #" + i + " = " + pfio.digital_read(0));
}
i = -1;
function anim() {
i++;
console.log("Pin #" + i + " on");
pfio.digital_write(i, 1);
if (i < 8) {
setTimeout(function () {
console.log("Pin #" + i + " off");
pfio.digital_write(i, 0);
if (i < 7) {
anim();
} else {
pfio.deinit();
}
}, 250);
}
}
anim();
pfio.init();
pfio.deinit();
var val = pfio.digital_read(pin); // returns 0 or 1
pfio.digital_write(pin, val);
var val = pfio.read_input(); // returns 0..255
var val = pfio.read_output(pin, val); // returns 0..255
pfio.write_output(val);