Button - lyzadanger/johnny-five GitHub Wiki
The Button
class constructs objects that represent a single digital Button attached to the physical board.
- pin A Number or String address for the Button pin (digital).
var button = new five.Button(5);
TinkerKit:
// Attached to TinkerKit's "Input 0"
var button = new five.Button("I0");
- options An object of property parameters.
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
pin | Number, String | 5, "I1" (Any digital pin on board) | The Number or String address of the pin the button is attached to, ie. 5 or "I1" | yes |
invert | Boolean | true or false | Invert the up and down values | no |
isPullup | Boolean | true or false | Initialize as a pullup button | no |
holdtime | Number | milliseconds | Number of milliseconds the button must be held until emitting a "hold" event. Defaults to 500ms | no |
button.on("press", function() { console.log( "Button has been pressed" ); });
### Shape
{ id: A user definable id value. Defaults to a generated uid pin: The pin address that the Button is attached to
downValue: 0 or 1, depending on invert or pullup upValue: 0 or 1, depending on invert or pullup holdtime: milliseconds }
### Usage
```js
var five = require("johnny-five"),
board = new five.Board();
board.on("ready", function() {
// Create a new `button` hardware instance.
var button = new five.Button(5);
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.