我有两个“Cylewet 25Pcs AC 1A 125V 3Pin SPDT 限位微动开关”,它们通常处于打开状态,并通过内部上拉电阻连接到两个 Pi 引脚。如果不加以注意,它们会自发调用已注册的函数,就像被按下一样。这可能是什么原因造成的?以下是代码的重要部分:
import RPi.GPIO as GPIO
def func(channel: int):
...
log.debug('The end breaker is pressed - channel %i', channel)
GPIO.setup([18,19], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(18, GPIO.FALLING, callback=func)
GPIO.add_event_detect(19, GPIO.FALLING, callback=func)
以下是日志:
2019-10-26 14:10:03,982 INFO last activity
2019-10-26 16:46:21,676 DEBUG module(func[xxx]): The end breaker is pressed - channel 18
2019-10-26 16:46:21,681 DEBUG module(func[xxx]): The end breaker is pressed - channel 18
2019-10-26 16:46:21,688 DEBUG module(func[xxx]): The end breaker is pressed - channel 19