【发布时间】:2021-08-25 14:41:25
【问题描述】:
我正在编写一段代码来控制连接到 Jetson nano 的三色灯。
每个 GPIO 引脚都专用于其颜色、引脚和状态。 说
Pins[0] = [Color.RED, pin=11, state=State.OFF]
Pins[1] = [Color.YEL, pin=13, state=State.SOLID_ON]
Pins[2] = [Color.GRN, pin=15, state=State.BLINK]
在 SetGPIO 函数中,我想像这样命令每个引脚
def SetGPIO(self, color, state):
if color == Color.RED:
Pins[0].state = state
elif color == Color.YEL:
Pins[1].state = state
elif color == Color.GRN:
Pins[2].state = state
然后在每 0.5 秒调用一次的更新函数中,
def Update(self):
foreach Pin in Pins
if Pins.state == State.off:
GPIO.output(Pins.pin, GPIO.LOW)
elif Pins.state == State.SOLID_ON:
GPIO.outpu(Pins.pin, GPIO.HIGH)
elif Pins.state == State.BLINK:
toggle GPIO(Pins.pin, state)
关于如何在python中实现这些功能有什么建议吗?
【问题讨论】: