Skip to content

Latest commit

 

History

History
92 lines (51 loc) · 1.46 KB

servo-continuous.md

File metadata and controls

92 lines (51 loc) · 1.46 KB

Servo - Continuous

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-continuous.js
const {Board, Servo} = require("johnny-five");
const keypress = require("keypress");

keypress(process.stdin);

const board = new Board();

board.on("ready", () => {

  console.log("Use Up and Down arrows for CW and CCW respectively. Space to stop.");

  const servo = new Servo.Continuous(10);

  process.stdin.resume();
  process.stdin.setEncoding("utf8");
  process.stdin.setRawMode(true);

  process.stdin.on("keypress", (ch, key) => {

    if (!key) {
      return;
    }

    if (key.name === "q") {
      console.log("Quitting");
      process.exit();
    } else if (key.name === "up") {
      console.log("CW");
      servo.cw();
    } else if (key.name === "down") {
      console.log("CCW");
      servo.ccw();
    } else if (key.name === "space") {
      console.log("Stopping");
      servo.stop();
    }
  });
});

 

License

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