Breadboard for "ESC - Keypress controlled ESCs"

esc-keypress.png

Fritzing diagram: esc-keypress.fzz

 

Run this example from the command line with:

node eg/esc-keypress.js
var five = require("johnny-five");
var keypress = require("keypress");
var board = new five.Board();

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

  var esc = new five.ESC(9);

  // Hold shift+arrow-up, shift+arrow-down to incrementally
  // increase or decrease speed.

  function controller(ch, key) {
    var isThrottle = false;
    var speed = esc.last ? esc.speed : 0;

    if (key && key.shift) {
      if (key.name === "up") {
        speed += 0.01;
        isThrottle = true;
      }

      if (key.name === "down") {
        speed -= 0.01;
        isThrottle = true;
      }

      if (isThrottle) {
        esc.speed(speed);
      }
    }
  }

  keypress(process.stdin);

  process.stdin.on("keypress", controller);
  process.stdin.setRawMode(true);
  process.stdin.resume();
});

 

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