【发布时间】:2021-04-04 20:14:53
【问题描述】:
好的,所以我有监控输入引脚的 pi_io.py 文件。每次输入状态更改时都会触发。我想要做的是在另一个文件的另一个类中订阅这个事件。这样事件就会在两个类中触发。
import RPi.GPIO as GPIO
class Pi_Io:
def __init__(self):
self.iscyclepressed = False
self.cyclestart = 13
# setup inputs
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.cyclestart, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(self.cyclestart, GPIO.BOTH,
callback=self.CycleStart_In, bouncetime=50)
def CycleStart_In(self, channel):
if not GPIO.input(self.cyclestart):
self.iscyclepressed = True
print("Cycle Button Pressed")
else:
self.iscyclepressed = False
print("Cycle Button Released")
Pi_Io()
while True:
pass
【问题讨论】:
标签: python events io raspberry-pi