I need to trigger a relay from a Button press and wait for a signal then release the relay. In the sample code below, that signal is b2. I'm new to Python and the Pi but having fun! :)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from gpiozero import Button
from signal import pause
import time
def first_button():
print("First Pressed")
while True: #do stuff...
time.sleep(1)
print("waiting...")
def second_button():
print("Second Pressed")
b1 = Button(23)
b1.when_pressed = first_button
b2 = Button(24)
b2.when_pressed = second_button
pause()
How do I detect a button press while an existing function called by a Button is still running?
In this solution you only switch the output on and off
Here a thread is started to do stuff: