Fritzing diagram: docs/breadboard/button.fzz
Run this example from the command line with:
node eg/button.js
var five = require("johnny-five"),
board, button;
board = new five.Board();
board.on("ready", function() {
// Create a new `button` hardware instance.
// This example allows the button module to
// create a completely default instance
button = new five.Button(2);
// Inject the `button` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
button: button
});
// Button Event API
// "down" the button is pressed
button.on("down", function() {
console.log("down");
});
// "hold" the button is pressed for specified time.
// defaults to 500ms (1/2 second)
// set
button.on("hold", function() {
console.log("hold");
});
// "up" the button is released
button.on("up", function() {
console.log("up");
});
});
Copyright (c) 2012-2014 Rick Waldron [email protected] Licensed under the MIT license. Copyright (c) 2015-2023 The Johnny-Five Contributors Licensed under the MIT license.