The Leds
class constructs a collection object containing multiple Led objects. Any method called on an Leds object will be called on each member of the Leds object with the same parameters.
See also:
Parameters
numsOrObjects An array of pins, Led parameter objects and/or Led objects:
Property Type Value/ Description Default Required numsOrObjects Array An element for each Led. Any valid Led parameters will work yes
Component Initialization
###With Pins
// Create three basic Leds
//
new five.Leds([9, 10, 11]);
###With Objects
// Create two Leds
//
new five.Leds([{
pin: 9
}, {
pin: 10
}]);
Usage
Control all members simultaneously:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var leds = new five.Leds([3, 5, 6]);
// Pulse all leds in the object.
leds.pulse();
});
Control a single Led in an Leds instance:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var leds = new five.Leds([9, 10]);
// Pulse the Led on pin 9.
leds[0].pulse();
});
Using multiple controllers in a single Leds instance:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var leds = new five.Leds([
{ controller: "PCA9685", pin: 0 }, // Attached to an Adafruit PWM shield
{ controller: "PCA9685", pin: 1 }, // Attached to an Adafruit PWM shield
{ pin: 3 } // Attached directly to the Arduino
]);
// Pulse both leds.
leds.pulse();
});
Using Led objects in Leds:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var ledA = new five.Led(9);
var ledB = new five.Led(10);
var lights = new five.Leds([ledA, ledB]);
// Set leds independently
ledA.brightness(20);
ledB.brightness(255);
// Pulse all Leds.
lights.pulse();
});
API
All methods and properties in the Led API are available on Leds
Events
Events are emitted on the individual Led objects so listeners must be attached there. See Led events
Examples
- LED - Fade callback
- LEDs - An array of LEDs
- LEDs - Controlling an array of LEDs
- Proximity - EVShield EV3 (IR)
- Proximity - EVShield EV3 (Ultrasonic)
- Expander - MCP23017
- Expander - MCP23008
- Expander - PCF8574
- Expander - PCF8575
- Expander - PCA9685
- Expander - 74HC595
- Expander - MUXSHIELD2, Digital Input and Output