1var gpio = require('gpio'); 2 3var led = gpio.open({ 4 id: 'led', 5 success: function() { 6 console.log('gpio: open led success') 7 }, 8 fail: function() { 9 console.log('gpio: open led failed') 10 } 11}); 12 13var key = gpio.open({ 14 id: 'key', 15 success: function() { 16 console.log('gpio: open key success') 17 }, 18 fail: function() { 19 console.log('gpio: open key failed') 20 } 21}); 22 23var vol = 0; 24var irqCnt = 0; 25key.onIRQ({ 26 cb: function() { 27 irqCnt = irqCnt + 1; 28 console.log('gpio: irq count ' + irqCnt); 29 vol = 1 - vol; 30 led.writeValue(vol); 31 console.log('gpio: led set value ' + vol); 32 33 vol = led.readValue(); 34 console.log('gpio: led get value ' + vol); 35 } 36}); 37 38console.log('gpio: ready to test') 39