UNPKG

johnny-five

Version:

The JavaScript Arduino Programming Framework.

72 lines (45 loc) 1.39 kB
# Button Run with: ```bash node eg/button.js ``` ```javascript 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(8); // 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"); }); }); ``` ## Breadboard/Illustration ![docs/breadboard/button.png](breadboard/button.png) ## Contributing All contributions must adhere to the [Idiomatic.js Style Guide](https://github.com/rwldrn/idiomatic.js), by maintaining the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt). ## License Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com> Licensed under the MIT license.