Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async raspberry pi gpio events in nodejs

Tags:

I connected a button to the Raspberry Pi GPIO ports:

http://adafruit.com/products/801

The pi-gpio node js module allows only to pull the current status but not waiting for a state change:

gpio.read(16, function(err, value) {     if(err) throw err;     console.log(value);    // The current state of the pin }); 

Is there any solution to bind events asynchronously?

In this example this would be whenever the button is pressed.

like image 703
jantimon Avatar asked Jan 21 '13 13:01

jantimon


1 Answers

I'd suggest using the module called onoff.

It has the ability to watch a value-file while not taxing the cpu with polling in intervals.

I made a small test-app with node.js to try out leds and buttons with it, you can check it out here.

like image 126
Olli K Avatar answered Sep 26 '22 00:09

Olli K