Created
June 19, 2013 19:53
-
-
Save synaptiko/5817470 to your computer and use it in GitHub Desktop.
Simple program combining temperature sensor and led through GPIO.
This file contains hidden or 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var gpio = require("gpio"); | |
var gpio10 = gpio.export(10, { | |
direction: "out", | |
ready: function() { | |
function readTemperature() { | |
var data = fs.readFileSync('/sys/bus/w1/devices/28-0000047c275a/w1_slave', { encoding: 'ascii' }); | |
var temperature; | |
data = data.split(' '); | |
temperature = parseFloat(data[data.length-1].split('=')[1]) / 1000.0; | |
temperature = Math.round(temperature * 10) / 10; | |
return temperature; | |
} | |
setInterval(function() { | |
var temperature = readTemperature(); | |
if (temperature > 30) { | |
gpio10.set(); | |
} | |
else { | |
gpio10.set(0); | |
} | |
console.log(temperature); | |
}, 500); | |
process.on('SIGINT', function() { | |
gpio10.set(0); | |
gpio10.unexport(); | |
process.exit(0); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment