gpio-promise
A fork of https://github.com/EnotionZ/GpiO to use es6
promises instead of callbacks. I have also changed the API slightly.
The code is written in es6
but compiled with 6to5 to es5
to be used with node as `require('gpio-promise').
Installation
Get node.js on your Raspberry Pi
On Raspbian, you can simply run apt-get install nodejs
,
otherwise, compile it
Usage
This library is an npm package, just define gpio-promise
in your package.json
dependencies or
npm install gpio-promise
Note: you must be running as root or have the proper priviledges to access the gpio headers
Standard setup
var GpioPin = ; var gpio4 = 4; gpio4 ;
The constructor also takes an optional object containing options
var gpio4 = 4 interval: 200;
Header direction "in"
If you plan to set the header voltage externally, use direction in
and read value from your program.
var GpioPin = ;var gpio4 = 4; gpio4 ;
API Methods
All API Methods below return Promise
.
var GpioPin = ;var gpio4 = 4; /** Open pin */gpio4;gpio4; // Or use the convenient methodsgpio4;gpio4; /** Set value */gpio4;gpio4;gpio4;gpio4; /** Toggle value between 1 and 0 */gpio4; /* * Unexport program when done */process;
EventEmitter
This library uses node's EventEmitter which allows you to watch for value changes and fire a callback.
var GpioPin = ;var gpio4 = 4; /** On every change */gpio4; /** Changing from 0 to 1 */gpio4; /** Changing from 1 to 0 */gpio4; // unbind a particular callback from the "change" eventgpio4; // unbind all callbacks from the "change" eventgpio4;
Tests
Run the tests with npm test
, these use a mock gpio
and are only testing this librarys interface.