Created
March 14, 2014 18:52
-
-
Save alexander-daniel/9554297 to your computer and use it in GitHub Desktop.
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 five = require("johnny-five"); | |
var board = new five.Board(); | |
var Stream = require('stream'); | |
var tmp36_stream = new Stream(); | |
var plotly = require('plotly')('demos','tj6mr52zgp'); | |
var data = [{ | |
x : [], | |
y : [], | |
stream : { | |
token : 'yglj648jt9', | |
maxpoints : 50 | |
} | |
}]; | |
var layout = { | |
fileopt : "extend", | |
filename : "NODEY Johnny Tempy Testy" | |
}; | |
board.on("ready", function() { | |
var tmp36 = new five.Sensor({ | |
pin: "A0", | |
freq: 250 | |
}); | |
plotly.plot(data,layout,function() { | |
plotly.stream('yglj648jt9', function(err,stream){ | |
tmp36_stream.pipe(stream); | |
}); | |
}); | |
tmp36.on("data", function() { | |
var voltage = this.value * 0.004882814; | |
// For Fahrenheit | |
var temperature_f = (((voltage - 0.5) * 100)*1.8) + 32; | |
// For Celsius | |
var temperature_c = ((voltage - 0.5) * 100); | |
var currentTime = Date.now(); | |
var date = new Date(currentTime); | |
var x = date; | |
var data = {x:x, y:temperature_c}; | |
tmp36_stream.emit('data', JSON.stringify(data)+'\n'); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment