Skip to content

Instantly share code, notes, and snippets.

@miyamoto-daisuke
Created December 18, 2014 08:59
Show Gist options
  • Save miyamoto-daisuke/47f5ce9cd5c6d42fbc8d to your computer and use it in GitHub Desktop.
Save miyamoto-daisuke/47f5ce9cd5c6d42fbc8d to your computer and use it in GitHub Desktop.
TriSens
console.log("TriSens");
var mraa = require('mraa');
console.log('MRAA Version: ' + mraa.getVersion());
var tempPin = new mraa.Aio(0);
var lightPin = new mraa.Aio(1);
var soundPin = new mraa.Aio(2);
var B = 3975; // B value of the thermistor
function toCelsius(v) {
var resistance = (1023 - v) * 10000 / v;
var celsius_temperature = 1 / (Math.log(resistance / 10000) / B + 1 / 298.15) - 273.15;
return celsius_temperature;
}
setInterval(function () {
var time = new Date();
console.log("==== " + time + " ====");
var tempValue = tempPin.read();
var lightValue = lightPin.read();
var soundValue = soundPin.read();
console.log("tempPin Value: " + toCelsius(tempValue));
console.log("lightPin Value: " + lightValue);
console.log("soundPin Value: " + soundValue);
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment