我有这个代码并且它运行两次罚款,而在第三次调用时我得到一个错误,好像我会通过Timestamp。我只传递过Tuple或无。
from pprint import pprint
from gpiozero import RGBLED
def signal(pri, newcolor):
signal.priority[pri] = newcolor
pprint(signal.priority)
try: signal.led.color = next(color for color in signal.priority if color is not None)
except StopIteration: signal.led.color = (0,0,0)
signal.led = RGBLED(red=11, green=9, blue=10)
signal.priority = 2*[None]
输出正在跟随
[None, (0, 1, 0)]
[None, (0, 0, 1)]
[None, (1, 1, 0)]
Traceback (most recent call last):
File "/home/pi/zrcrasp.py", line 137, in <module>
signal(1, (1,1,0))
File "/home/pi/zrcrasp.py", line 10, in signal
try: signal.led.color = next(color for color in signal.priority if color is not None)
TypeError: 'Timestamp' object is not callable
程序的各个部分使用函数来发出任何类型的错误信号,但如果高优先级短红色闪烁结束,则优先级较低的绿色应继续。如果没有较低优先级 - None
,那么led将被关闭(这是except
语句)
最低的索引是最高优先级。