Included in the gpiozero button class is seting
class gpiozero.
Button
(pin, *, pull_up=True, active_state=None, bounce_time=None, hold_time=1, hold_repeat=False, pin_factory=None)[source]
It has two buttons: Left is Pull Up. Right is Pull Down. How do you tell the difference? Well, Pull up has ground on the button and GPIO18 is where the power is provided from. The Right Button, has 3.3V going into the button and Pull-down to ground on the other side.
Pull Up Button not pressed
Pull Down Button not pressed
Pull Up Button not pressed
Pull Down Button not pressed
*** Pull Up Button is pressed ***
Pull Down Button not pressed
Pull Up Button not pressed
Pull Down Button not pressed
Pull Up Button not pressed
Pull Down Button not pressed
Pull Up Button not pressed
Pull Down Button not pressed
Pull Up Button not pressed
*** Pull Down Button is pressed ***
Pull Up Button not pressed
Pull Down Button not pressed
Pull Up Button not pressed
Pull Down Button not pressed
Pull Up Button not pressed
I added on GPIO 17 a LED that turns on when Pull Up Button is pressed and turns off when the Pull Up button is released. I could add a second LED for the Pull Down Button.
from gpiozero import Button, LED from time import sleep pu_led_red = LED(17) pu_button = Button(18, pull_up=True) pd_button = Button(24, pull_up=False) while True: if pu_button.is_pressed: print("*** Pull Up Button is pressed ***") pu_led_red.on() else: print("Pull Up Button not pressed") pu_led_red.off() sleep(2) if pd_button.is_pressed: print("*** Pull Down Button is pressed ***") else: print("Pull Down Button not pressed") sleep(2)