Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created March 17, 2016 19:17
Show Gist options
  • Select an option

  • Save rwaldron/b4eb8e0fdf31db7a78dd to your computer and use it in GitHub Desktop.

Select an option

Save rwaldron/b4eb8e0fdf31db7a78dd to your computer and use it in GitHub Desktop.
var five = require("johnny-five");
var Particle = require("particle-io");
var app = require("express")();
var http = require("http").Server(app);
var io = require("socket.io")(http);
app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});
var board = new five.Board({
io: new Particle({
token: process.env.VIBRATOR_TOKEN,
deviceId: process.env.VIBRATOR_DEVICE_ID
})
});
board.on("ready", function() {
var vibe = new five.Motor({
pins: { pwm: "D0", dir: "D2" }
});
io.on("connection", function(socket) {
socket.on("instruction", function(data) {
vibe[data.command](data.speed);
});
});
http.listen(3000, function() {
console.log("http://localhost:3000");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment