onoff
Version:
GPIO access and interrupt detection with Node.js
24 lines (17 loc) • 541 B
JavaScript
;
const Gpio = require('../onoff').Gpio; // Gpio class
const led = new Gpio(17, 'out'); // Export GPIO17 as an output
let stopBlinking = false;
// Toggle the state of the LED connected to GPIO17 every 200ms
const blinkLed = _ => {
if (stopBlinking) {
return led.unexport();
}
led.read()
.then(value => led.write(value ^ 1))
.then(_ => setTimeout(blinkLed, 200))
.catch(err => console.log(err));
};
blinkLed();
// Stop blinking the LED after 5 seconds
setTimeout(_ => stopBlinking = true, 5000);