Created
August 10, 2012 06:08
-
-
Save EnotionZ/3311636 to your computer and use it in GitHub Desktop.
Cycle voltage on Raspberry Pi gpio header in node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gpio = require('gpio'); | |
var header4, header17, intervalTimer; | |
header4 = gpio.export(4); | |
header17 = gpio.export(17, { | |
ready: function() { | |
intervalTimer = setInterval(function() { | |
header4.set(); | |
setTimeout(function() { header4.reset(); }, 500); | |
}, 1000); | |
header4.on('change', function(val) { header17.set(1-val); }); | |
} | |
}); | |
// after 10 seconds, reset all the headers, unexport and quit program | |
setTimeout(function() { | |
clearInterval(intervalTimer); | |
header4.removeAllListeners('valueChange'); | |
header4.reset(); | |
header4.unexport(); | |
header17.reset(); | |
header17.unexport(function(){ | |
process.exit(); | |
}); | |
}, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment