UNPKG

johnny-five-electron

Version:

Temporary fork to support Electron (to be deprecated)

92 lines (65 loc) 1.36 kB
var five = require("../lib/johnny-five.js"), board = new five.Board(); board.on("ready", function() { var motor; /* ArduMoto Motor A pwm: 3 dir: 12 Motor B pwm: 11 dir: 13 AdaFruit Motor Shield Motor A pwm: ? dir: ? Motor B pwm: ? dir: ? Bi-Directional Motors can be initialized by: new five.Motor([ 3, 12 ]); ...is the same as... new five.Motor({ pins: [ 3, 12 ] }); ...is the same as... new five.Motor({ pins: { pwm: 3, dir: 12 } }); */ motor = new five.Motor({ pins: { pwm: 3, dir: 12 } }); board.repl.inject({ motor: motor }); motor.on("start", function() { console.log("start"); }); motor.on("stop", function() { console.log("automated stop on timer"); }); motor.on("forward", function() { console.log("forward"); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { motor.reverse(50); }); }); motor.on("reverse", function() { console.log("reverse"); // demonstrate stopping after 5 seconds board.wait(5000, function() { motor.stop(); }); }); // set the motor going forward full speed motor.forward(255); });