UNPKG

johnny-five

Version:

Firmata based Arduino Programming Framework.

41 lines (31 loc) 737 B
var five = require("../lib/johnny-five.js"), board = new five.Board({ debug: true }); board.on("ready", function() { var range, pan, tilt, joystick; range = [ 0, 170 ]; // Servo to control panning pan = new five.Servo({ pin: 9, range: range }); // Servo to control tilt tilt = new five.Servo({ pin: 10, range: range }); // Joystick to control pan/tilt // Read Analog 0, 1 // Limit events to every 50ms joystick = new five.Joystick({ pins: [ "A0", "A1" ], freq: 100 }); // Center all servos (five.Servos()).center(); joystick.on("axismove", function() { tilt.move( Math.ceil(170 * this.fixed.y) ); pan.move( Math.ceil(170 * this.fixed.x) ); }); });