Following are the lines used to configure the push button. On line (6), the class we use is Button. In GPIOZero, we use a Button class for any input device that can be either on or off, such as buttons and switches:
button = Button(BUTTON_GPIO_PIN,
pull_up=True, bounce_time=0.1) # (6)
button.when_pressed = pressed # (7)
On line (7), we register the pressed() callback handler with our button instance.
Here are the meanings of the parameters to the Button constructor on line (6):
- The first parameter is the button's GPIO pin (BUTTON_GPIO_PIN == 23).
- The second parameter, pull_up=True, enables an internal pull-up resistor for GPIO 23. Pull-up and pull-down resistors are an important concept in digital electronics. We're are going to skip over this concept for now because we will be covering the importance and use of pull-up and pull-down resistors in greater detail in Chapter 6, Electronics...