0
我目前有幾個槓桿型關閉開關,我希望打印狀態,只要它獨立開關所有其他開關。Python GPIO add_event_detect每個狀態單獨
到目前爲止,我已經走到這一步:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.IN) # switch 2
GPIO.setup(11, GPIO.IN) # switch 3
def print_func(pin):
if GPIO.input(7) == 0:
print "switch 2 on"
elif GPIO.input(7) == 1:
print "switch 2 off"
elif GPIO.input(11) == 0:
print "switch 3 on"
elif GPIO.input(11) == 1:
print "switch 3 off"
GPIO.add_event_detect(7, GPIO.BOTH, callback=print_func, bouncetime=300)
GPIO.add_event_detect(11, GPIO.BOTH, callback=print_func, bouncetime=300)
while True:
sleep(1)
然而,這並不讓我在任何地方。我無法弄清楚如何剛纔提到的槓桿只是移動的狀態,沒有通過循環提及每個人的狀態。
任何幫助將非常感謝!