我正在 raspberry pi 3 上編寫 python 代碼。我正在輸入通道 21 上注冊一個事件,以檢查濕度檢測。我收到此錯誤運行時錯誤:無法添加邊緣檢測。我的代碼是:import RPi.GPIO as GPIOimport sys,osimport timeimport datetimechannel = 21led_output = 18GPIO.setmode(GPIO.BCM)GPIO.setwarnings(False)GPIO.setup(channel, GPIO.IN)GPIO.setup(led_output, GPIO.OUT)def callback(channel): filehandle = open("output.txt", "w") or die ("Could not write out") if GPIO.input(channel) == 1: print ("Water Detected!") filehandle.write("1") GPIO.output(led_output, GPIO.LOW) else: print ("Water Not Detected!") filehandle.write("0") GPIO.output(led_output, GPIO.HIGH) filehandle.close() GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) GPIO.add_event_callback(channel, callback) print(GPIO.input(channel)) while True: time.sleep(5)
樹莓派添加事件。運行時錯誤:無法添加邊緣檢測
慕桂英3389331
2021-08-14 16:48:18