onoff
Version:
GPIO access and interrupt detection with Node.js
15 lines (10 loc) • 436 B
JavaScript
;
const Gpio = require('../onoff').Gpio; // Gpio class
const led = new Gpio(17, 'out'); // Export GPIO17 as an output
// Toggle the state of the LED connected to GPIO17 every 200ms
const iv = setInterval(_ => led.writeSync(led.readSync() ^ 1), 200);
// Stop blinking the LED after 5 seconds
setTimeout(_ => {
clearInterval(iv); // Stop blinking
led.unexport(); // Unexport GPIO and free resources
}, 5000);