@iiot2k/gpiox
Version:
Input/Output on any gpio library
41 lines (31 loc) • 858 B
JavaScript
/*
* example pulse gpio output
*
* run:
* > node pulse_gpio.js
*
*/
;
const gpiox = require("../gpiox");
const PIN_OUTPUT = 20;
const PULSE1 = 200; // ms
const PULSE2 = 5000; // ms
console.log("*** puls gpio node.js example ***");
console.log("stop program with Ctrl+C");
// init gpio
gpiox.init_gpio(PIN_OUTPUT, gpiox.GPIO_MODE_OUTPUT, 0);
console.log("pulse", PULSE1 + "ms");
gpiox.pulse_gpio(PIN_OUTPUT, PULSE1);
// after 5 pulse longer
var id_tout = setTimeout(function() {
console.log("pulse", PULSE2 + "ms");
gpiox.pulse_gpio(PIN_OUTPUT, PULSE2);
}, 1000);
// prevent stop program
var id_intv = setInterval(function() {}, 100);
process.on('SIGINT', () => {
clearTimeout(id_tout);
clearInterval(id_intv);
console.log(" -> program stopped");
process.exit();
});