UNPKG

@iiot2k/gpiox

Version:

Input/Output on any gpio library

51 lines (39 loc) 1.06 kB
/* * example pulse gpio output * * run: * > node pulse_gpio.js * */ "use strict"; const gpiox = require("../gpiox"); const PIN_OUTPUT = 20; const PULSE1 = 5; // ms const PULSE2 = 100; // ms const PULSE3 = 10; // ms const PULSE4 = 500; // ms console.log("*** puls gpio node.js example ***"); // init gpio gpiox.init_gpio(PIN_OUTPUT, gpiox.GPIO_MODE_OUTPUT, 0); console.log("pulse", PULSE1 + "ms"); gpiox.pulse_gpio(PIN_OUTPUT, PULSE1); // after 500ms PULSE2 setTimeout(function() { console.log("pulse", PULSE2 + "ms"); gpiox.pulse_gpio(PIN_OUTPUT, PULSE2); }, 500); // after 500ms PULSE3 setTimeout(function() { console.log("pulse", PULSE3 + "ms"); gpiox.pulse_gpio(PIN_OUTPUT, PULSE3); }, 1000); // after 500ms PULSE4 setTimeout(function() { console.log("pulse", PULSE4 + "ms"); gpiox.pulse_gpio(PIN_OUTPUT, PULSE4); }, 1500); // after 500ms stop program setTimeout(function() { gpiox.deinit_gpio(PIN_OUTPUT); console.log(" -> program stopped"); }, 2000);