The Motors class constructs a collection object containing multiple motor objects. Any method called on a Motors object will be called on each entry of the Motors object with the same parameters.

See also:

Parameters

  • numsOrObjects An array of pins, motor parameter objects and/or Motor objects:

    PropertyTypeValue/ DescriptionDefaultRequired
    numsOrObjectsArrayAn entry for each motor. Any valid motor parameters will workyes

Component Initialization

With Pins

// Create three non-directional motors
//
new five.Motors([9, 10, 11]);

With Objects

// Create two customized motors
//
new five.Motors([{
  pins: {
    pwm: 3,
    dir: 12
  }
}, {
  pins: {
    pwm:9,
    dir:8,
    cdir: 11  
  }
}]);

Usage

Control all members simultaneously:

var five = require("johnny-five");
var board = new five.Board();

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

  var motors = new five.Motors([
    { dir: 7, pwm: 6 },
    { dir: 8, pwm: 9 },
  ]);

  motors.forward(255);
});

Control a single motor in a Motors instance:

var five = require("johnny-five");
var board = new five.Board();

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

  var motors = new five.Motors([
    { dir: 4, cdir: 5, pwm: 6 },
    { dir: 7, cdir: 8, pwm: 9 },
  ]);


  // Sweep the motor on pin 9 from 0-180 and repeat.
  motors[0].forward(255);
});

Using multiple controllers in a single Motors instance:

var five = require("johnny-five");
var board = new five.Board();

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

  var motors = new five.Motors([
    { controller: "PCA9685", pins: { dir: 4, cdir: 5, pwm: 6 } },
    { pins: { dir: 4, cdir: 5, pwm: 6 } }
  ]);

  // Sweep both motors from 0-180 and repeat.
  motors.forward(255);
});

API

All methods in the Motor API are available on Motors

Examples

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