I want to call a function from a Switch(test) wired to the Raspberry. With the code posted below the function(asdf) is running when I click the Button on the UI. I deleted all the other stuff to make it look clear. But how can I call the (test) function when the GPIO get´s LOW?
import RPi.GPIO as GPIO
from tkinter import *
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(20,GPIO.IN) # If Button is not pressed, Signal is HIGH
fenster = Tk()
fenster.geometry("100x100")
def test():
if(GPIO.input(20)==False):
print("a")
def asdf():
print("asdf")
b3=Button(fenster,text ="Referenzfahrt", command=asdf)
b3.config()
b3.pack(side="top")
fenster.mainloop()
I solved it:
GPIO.add_event_detect(20, GPIO.RISING, callback=lambda x: test(), bouncetime=1000)
With this line it calls the function when I press the Button