Permalink
017e5f1 Jun 8, 2018
4 contributors

Users who have contributed to this file

@rwaldron @Resseguie @dtex @BrianGenisio
94 lines (55 sloc) 1.25 KB

Servo - Sweep

Servo on pin 10

Servo connected to pin 10. Requires servo on pin that supports PWM (usually denoted by ~).

docs/breadboard/servo.png

Fritzing diagram: docs/breadboard/servo.fzz

 

Run this example from the command line with:

node eg/servo-sweep.js
var five = require("johnny-five"),
  board = new five.Board();

board.on("ready", function() {
  var servo = new five.Servo({
    pin: 10,
    startAt: 90
  });
  var lap = 0;

  servo.sweep().on("sweep:full", function() {
    console.log("lap", ++lap);

    if (lap === 1) {
      this.sweep({
        range: [40, 140],
        step: 10
      });
    }

    if (lap === 2) {
      this.sweep({
        range: [60, 120],
        step: 5
      });
    }

    if (lap === 3) {
      this.sweep({
        range: [80, 100],
        step: 1
      });
    }

    if (lap === 5) {
      process.exit(0);
    }
  });
});

 

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.