我尝试在没有 GPIO 的机器上开发一些代码。作为 GPIO 库,我选择了一个 gpiozero 来编写我的代码,而无需访问树莓派的 gpio。我的问题,我无法在代码中使用 .when_pressed 事件。我模拟按钮的状态变化,但没有调用该函数。
Device.pin_factory = MockFactory()
def interrupt_Event(channel):
print("%s puted in the queue", channel)
InputPin.Device.pin_factory.pin(channel)
InputPin.when_pressed = interrupt_Event
def main():
try:
while True:
time.sleep(1)
InputPins[channel].pull=drive_high()
time.sleep(0.1)
print("State CHANNEL %s" % channel)
print(InputPins[channel].state)
InputPins[channel].drive_low()
直到现在我不知道出了什么问题。