Permalink
017e5f1 Jun 8, 2018
4 contributors

Users who have contributed to this file

@rwaldron @Resseguie @dtex @BrianGenisio
101 lines (57 sloc) 1.69 KB

Servo - Drive

Servos on pins 9 and 10

Servos connected to pins 9 and 10. Requires servos on pins that support PWM (usually denoted by ~).

docs/breadboard/servo-two.png

Fritzing diagram: docs/breadboard/servo-two.fzz

 

Run this example from the command line with:

node eg/servo-drive.js
var five = require("johnny-five"),
  board, wheels;

board = new five.Board();

board.on("ready", function() {

  wheels = {};

  // Create two servos as our wheels
  wheels.left = new five.Servo({
    pin: 9,
    // `type` defaults to standard servo.
    // For continuous rotation servos, override the default
    // by setting the `type` here
    type: "continuous"

  });

  wheels.right = new five.Servo({
    pin: 10,
    // `type` defaults to standard servo.
    // For continuous rotation servos, override the default
    // by setting the `type` here
    type: "continuous",
    invert: true // one wheel mounted inverted of the other
  });

  wheels.both = new five.Servos().stop(); // reference both together

  // Add servos to REPL (optional)
  this.repl.inject({
    wheels: wheels
  });

  // Drive forwards
  // Note, cw() vs ccw() might me different for you
  // depending on how you mount the servos
  wheels.both.cw();

  // Stop driving after 3 seconds
  this.wait(3000, function() {
    wheels.both.stop();
  });

});

 

License

Copyright (c) 2012-2014 Rick Waldron waldron.rick@gmail.com Licensed under the MIT license. Copyright (c) 2015-2018 The Johnny-Five Contributors Licensed under the MIT license.