forked from rwaldron/johnny-five
-
Notifications
You must be signed in to change notification settings - Fork 2
Button
Rick Waldron edited this page Nov 14, 2015
·
26 revisions
The Button
class constructs objects that represents a single Button attached to the physical board.
-
pin A Number or String address for the Button pin (digital).
var button = new five.Button(8);
// Attached to an analog pin var button = new five.Button("A0");
-
Options An object of property parameters.
Property Type Value/Description Default Required pin Number, String Digital Pin. The Number or String address of the pin the button is attached to, ie. 5 or “I1” yes invert Boolean true
,false
. Invert the up and down values. This is useful for inverting button signals when the pin itself doesn’t have built-in pullup resistor capabilities.false
no isPullup Boolean true
,false
. Initialize as a pullup buttonfalse
no holdtime Number Time in milliseconds that the button must be held until emitting a "hold" event. 500ms no
Property Name | Description | Read Only |
---|---|---|
id |
A user definable id value. Defaults to a generated uid | No |
pin |
The pin address that the Button is attached to | No |
downValue |
0 or 1, depending on invert or pullup | No |
upValue |
0 or 1, depending on invert or pullup | No |
holdtime |
milliseconds | No |
new five.Button(2);
new five.Button({
pin: 2,
invert: true
});
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Create a new `button` hardware instance.
var button = new five.Button(2);
button.on("hold", function() {
console.log( "Button held" );
});
button.on("press", function() {
console.log( "Button pressed" );
});
button.on("release", function() {
console.log( "Button released" );
});
});
-
hold The button has been held for
holdtime
milliseconds -
down, press The button has been pressed.
-
up, release The button has been released.