The Relays class constructs a collection object containing multiple relay objects. Any method called on a Relays collection will be called on each member of the Relays collection with the same parameters.

Once instantiated, a Relays collection object is static.

For working with a single relay check out the Relay class.

Parameters

  • numsOrObjects An array of pins, relay parameter objects and/or Relay objects:

    PropertyTypeValue/ DescriptionDefaultRequired
    numsOrObjectsArrayAn element for each relay. Any valid relay parameters will workyes

Component Initialization

With Pins

// Create three basic relays
//
new five.Relays([9, 10, 11]);

With Objects

// Create two customized relays
//
new five.Relays([{
  pin: 9, 
  type: "NO",
}, {
  pin: 10, 
  type: "NC",
}]);

Usage

Control all members simultaneously:

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

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

  var relays = new five.Relays([9, 10]);

  // Close all relay circuits.
  relays.close();
});

Control a single relay in a Relays instance:

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

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

  var relays = new five.Relays([9, 10]);

  // Close the relay on pin 9.
  relays[0].close();
});

Using Relay objects in Relays:

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

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

  var r1 = new five.Relay(9);
  var r2 = new five.Relay(10);

  var joints = new five.Relays([r1, r2]);

  // Close all relays independently
  r1.close();
  r2.close();

  // Open all relays.
  relays.open();
});

API

All methods and properties in the Relay API are available on Relay

Events

Events are emitted on the individual Relay objects so listeners must be attached there. See Relay events

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