我正在 raspberry pi 3 上編寫(xiě) python 代碼。我正在輸入通道 21 上注冊(cè)一個(gè)事件,以檢查濕度檢測(cè)。我收到此錯(cuò)誤運(yùn)行時(shí)錯(cuò)誤:無(wú)法添加邊緣檢測(cè)。我的代碼是: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)
樹(shù)莓派添加事件。運(yùn)行時(shí)錯(cuò)誤:無(wú)法添加邊緣檢測(cè)
慕桂英3389331
2021-08-14 16:48:18