Skip to content

Instantly share code, notes, and snippets.

@alexander-daniel
Created April 7, 2014 17:21
Show Gist options
  • Save alexander-daniel/10024471 to your computer and use it in GitHub Desktop.
Save alexander-daniel/10024471 to your computer and use it in GitHub Desktop.
sensing sensors avoiding censorship sensing sensors
var plotly = require('plotly')('workshop','v6w5xlbx9j');
var five = require("johnny-five");
var board = new five.Board();
// plotly init data
var data = [
{x:[], y:[], stream:{token:'25tm9197rz', maxpoints:200}},
{x:[], y:[], stream:{token:'unbi52ww8a', maxpoints:200}}
];
var layout = {fileopt : "overwrite", filename : "nodey arduino!"};
// lets do this
board.on("ready", function () {
var photoresistor = new five.Sensor({ pin: "A0", freq: 50 });
var potentiometer = new five.Sensor({ pin: "A1", freq: 50 });
plotly.plot(data,layout,function (err, res) {
if (err) console.log(err);
console.log(res);
var photoresistor_stream = plotly.stream('25tm9197rz', function (err, res) {
if (err) console.log(err);
console.log(res);
});
var potentiometer_stream = plotly.stream('unbi52ww8a', function (err, res) {
if (err) console.log(err);
console.log(res);
});
photoresistor.scale([ 0, 1 ]).on("data", function () {
data = {
x : getDateString(),
y : this.value
};
photoresistor_stream.write(JSON.stringify(data)+'\n');
});
potentiometer.scale([ 0, 1 ]).on("data", function () {
data = {
x : getDateString(),
y : this.value
};
potentiometer_stream.write(JSON.stringify(data)+'\n');
});
});
});
// little helper function to get a nicely formatted date string
function getDateString () {
var time = new Date();
var datestr = new Date(time - 14400000).toISOString().replace(/T/, ' ').replace(/Z/, '');
return datestr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment