-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Switch
Rick Waldron edited this page May 10, 2016
·
6 revisions
The Switch
class constructs objects that represent a single Switch attached to the physical board.
-
pin A Number or String address for the pin.
-
options An object of property parameters.
Property Type Value/Description Default Required pin Number, String Any Pin. The Number or String address of the Switch pin yes type String "NO" or "NC". Indicate if the switch is "normally open" or "normally closed" "NO" no
Property Name | Description | Read Only |
---|---|---|
id |
A user definable id value. Defaults to a generated uid. | No |
pin |
The pin value. | No |
isClosed |
Boolean indicating whether the switch is closed. | Yes |
isOpen |
Boolean indicating whether the switch is open. | Yes |
new five.Switch(8);
// Options object with pin property
new five.Switch({
pin: 8
});
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var spdt = new five.Switch(8);
var led = new five.Led(13);
spdt.on("open", function() {
led.off();
});
spdt.on("close", function() {
led.on();
});
});
-
open The
open
event will emit when the circuit opens. -
close The
close
event will emit when the circuit closes.
Switch
supports a Switches
collection class, which allows multiple Switch
instances to be controlled via a single instance object. Events emitted by instances of the Switch
class are forwarded through instances of the Switches
class. The handler receives the instance that emitted the event as the first parameter.
new five.Switches([ 2, 3, 4, 5 ]);
new five.Switches([ { pin: 2 }, { pin: 3 }, { pin: 4 }, { pin: 5 } ]);
new five.Switches([ switch1, switch2, switch3 ]);