Servo on pin 10

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

servo.png

Fritzing diagram: servo.fzz

 

Run this example from the command line with:

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

board.on("ready", () => {
  const servo = new Servo({
    pin: 10,
    startAt: 90
  });
  let lap = 0;

  servo.sweep().on("sweep:full", () => {
    console.log(`lap ${++lap}`);

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

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

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

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

 

Component Classes in this example:

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub