-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ESCs
Rick Waldron edited this page Mar 22, 2023
·
8 revisions
The ESCs
class constructs a collection object containing multiple ESC objects. Any method called on an ESCs object will be called on each member of the ESCs object with the same parameters.
See also:
-
numsOrObjects An array of pins, ESC parameter objects and/or ESC objects:
Property Type Value/ Description Default Required numsOrObjects Array An element for each ESC. Any valid ESC parameters will work yes
###With Pins
// Create two basic ESCs
//
new five.ESCs([9, 10]);
###With Objects
// Create two ESCs
//
new five.ESCs([{
pin: 9
}, {
pin: 10
}]);
Control all members simultaneously:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var escs = new five.ESCs([3, 5]);
// Set all ESCs to max.
escs.throttle(100);
});
Control a single ESC in an ESCs instance:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var escs = new five.ESCs([9, 10]);
// Set the ESC on pin 9 to 90% of max speed.
escs[0].throttle(90);
});
Using multiple controllers in a single ESCs instance:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var escs = new five.ESCs([
{ controller: "PCA9685", pin: 0 }, // Attached to an Adafruit PWM shield
{ pin: 3 } // Attached directly to the Arduino
]);
// Set both escs to 75% of max speed.
escs.throttle(75);
});
Using ESC objects in ESCs:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var escA = new five.ESC(9);
var escB = new five.ESC(10);
var motors = new five.ESCs([escA, escB]);
// Set ESCs independently
escA.throttle(20);
escB.throttle(90);
// Set all ESCs to max speed.
escs.throttle(100);
});
All methods and properties in the ESC API are available on ESCs
Events are emitted on the individual ESC objects so listeners must be attached there. See ESC events