Circuits and Buttons
To create a button or a switch, you just need a circuit that can be easily connected and disconnected. Like an LED circuit, a button circuit can be created by connecting one wire to a data pin and another wire to a ground pin. To "close" the circuit (which is like pressing a button) you connect the two wires, either by touching them to each other or connecting them to a piece of hardware (like a button or switch) that can be used to open and close the circuit. An "open" button is equivalent to the button "up" event, while a "closed" circuit is like the button "down" event.
As with LED circuits, you can create a button circuit on any of pins 0, 2, 3, 6, and 12.
Creating Button Circuits
To create a button circuit you'll need a data pin, two wires, and a ground pin.
- Connect a wire to your numbered data pin.
- Connect a different wire to a ground pin.
- Using code, create a new button object and event handler.
\\ Create a button attached pin 0 var myButton = createButton(0); \\ Add an event handler to the new button onBoardEvent(myButton, "down", function() { console.log("button pressed"); });