I am working on a camera using python on a raspberry, and for the buttons setup I am using gpiozero library.
Can the function button.when_pressed be used twice on the same script?
if not, how can I re-initialize the button?
Please find a test code below :
import RPi.GPIO as GPIO from gpiozero import Button GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) button = Button(21) status = 0 def action1(): print("Action 1") status = 1 def action2(): print("Action 2") status = 0 while True: if status == 0: button.when_pressed = action1 elif status ==1: button.when_pressed = action2
With this test I just realized that the button.when_pressed = action2 is not active.
How can I ask the raspberry to change the event to action 2 when the button “button” is pressed.