Back to Johnny Five

Buttons - Collection w/ AT42QT1070

docs/button-collection-AT42QT1070.md

2.1.01.4 KB
Original Source
<!--remove-start-->

Buttons - Collection w/ AT42QT1070

<!--remove-end-->
Breadboard for "Buttons - Collection w/ AT42QT1070"

Fritzing diagram: docs/breadboard/button-collection-AT42QT1070.fzz

 

Run this example from the command line with:

bash
node eg/button-collection-AT42QT1070.js
javascript
var five = require("../");
var board = new five.Board();

board.on("ready", function() {
  // The "shared property" interface, allows
  // writing a more succint initialization,
  // as it's effectively a short hand for:
  //
  // var buttons = new five.Buttons([
  //   { pin: 2, invert: true },
  //   { pin: 3, invert: true },
  //   { pin: 4, invert: true },
  //   { pin: 5, invert: true },
  //   { pin: 6, invert: true },
  // });
  //
  var buttons = new five.Buttons({
    pins: [2, 3, 4, 5, 6],
    invert: true,
  });

  buttons.on("press", function(button) {
    console.log("Pressed: ", button.pin);
  });

  buttons.on("release", function(button) {
    console.log("Released: ", button.pin);
  });
});

 

<!--remove-start-->

License

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.

<!--remove-end-->