Skip to content

Instantly share code, notes, and snippets.

@synaptiko
Created June 19, 2013 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save synaptiko/5817470 to your computer and use it in GitHub Desktop.
Save synaptiko/5817470 to your computer and use it in GitHub Desktop.
Simple program combining temperature sensor and led through GPIO.
#!/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