Skip to content

Instantly share code, notes, and snippets.

@alexander-daniel
Created March 13, 2014 19:56
Show Gist options
  • Save alexander-daniel/9535707 to your computer and use it in GitHub Desktop.
Save alexander-daniel/9535707 to your computer and use it in GitHub Desktop.
johnny-five plotly arduino
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