Created
March 13, 2014 19:56
-
-
Save alexander-daniel/9535707 to your computer and use it in GitHub Desktop.
johnny-five plotly arduino
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"), | |
board, photoresistor; | |
var Stream = require('stream'); | |
var sensorstream = new Stream(); | |
board = new five.Board(); | |
var plotly = require('plotly')('demos','tj6mr52zgp'); | |
var data = [{ | |
x : [], | |
y : [], | |
stream : { | |
token : 'lu1xzzrt70', | |
maxpoints : 200 | |
} | |
}]; | |
var layout = { | |
fileopt : "extend", | |
filename : "NODEY Johnny 8898" | |
}; | |
board.on("ready", function() { | |
photoresistor = new five.Sensor({ | |
pin: "A2", | |
freq: 50 | |
}); | |
plotly.plot(data,layout,function() { | |
plotly.stream('lu1xzzrt70', function(err,stream){ | |
sensorstream.pipe(stream); | |
}); | |
}); | |
photoresistor.on("data", function() { | |
var currentTime = Date.now(); | |
var x = currentTime; | |
console.log(this.value); | |
var y = this.value; | |
var data = {x:x, y:y}; | |
sensorstream.emit('data', JSON.stringify(data)+'\n'); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment