I've following this tutorial but using the setup shown below. I can get my LED working fine, but the button.watch()
doesn't seem to listen to the button.
When I run this python script & then rerun my node app button.watch()
works as expected... so I'm guessing the python script is opening a connection & then it's staying open for the node app to use.
What am I doing wrong that when I first run my node app I can't get button.watch()
to actually listen to button events?
node - v4.2.1
Linux 4.1.13+ #826 PREEMPT Fri Nov 13 20:13:22 GMT 2015 armv6l GNU/Linux
var Gpio = require('onoff').Gpio,
led = new Gpio(18, 'out'),
button = new Gpio(23, 'in', 'both');
console.log('boot');
led.writeSync(1);
function exit() {
led.unexport();
button.unexport();
process.exit();
}
console.log(
//the value of this is 0 right now
button.readSync()
);
button.watch(function(err, value) {
//these console.log commands never get fired
console.log(value);
led.writeSync(value);
console.log('button valued changed');
});
setInterval(function(){
led.writeSync(led.readSync() ^ 1);
}, 1000);
process.on('SIGINT', exit);