Buttons
A button is one of the simplest input devices you can connect to your BeagleBone. To sense the state of a button, we only need to use a single GPIO pin configured as an input. We haven't used a GPIO input yet, so let's take a look at a simple example first.
For this circuit, you will need:
- Breadboard
- 1x tactile switches
- 1x 10 kΩ resistors
- Jumper wires
A tactile switch is a type of momentary push button, meaning that it is only engaged while it is held down and returns to its default state when released. They are widely available from stores such as Adafruit and SparkFun, and it is also one of the more breadboard-friendly types of switches. Depending on the variety of tactile switch, it might require straightening the pins with a pair of pliers to get it to lock into your breadboard. Wire the switch to GPIO0_30 (P9.11), as shown in the figure:
Now run the following code and press the button; you should see a value of 0
normally and 1
when you press the button:
from bbio...