Switch - dtex/johnny-five GitHub Wiki
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.