我对python和编码来说是一个非常陌生的人,想要在Raspberry Pi3和Sense Hat上做一些工作,请原谅任何滥用术语的行为。我试图使用操纵杆来调用一个脚本,该脚本每次按下时都会在Sense Hat的LED矩阵上显示15秒的计时器。到目前为止,当按下操纵杆时,我已经能够使脚本运行一次,但是如果再次按下操纵杆,则无法使脚本再次运行。反正有可能使之成为可能吗?
from sense_hat import SenseHat
from time import sleep
sense = SenseHat()
e = (0, 0, 0)
w = (255, 255, 255)
G = [0, 255, 0]
R = [255, 0, 0]
X = [0, 0, 0]
s = 15
timer = []
def time():
for i in range(64):
if i < s:
timer.append(G)
else:
timer.append(X)
sense.set_pixels(timer)
for i in range(0, s):
sleep(1)
timer[i] = R
sense.set_pixels(timer)
for i in range(0, 10):
sense.clear()
sleep(0.1)
sense.set_pixels(timer)
sleep(0.1)
sense.clear()
while True:
for event in sense.stick.get_events():
if event.action == "pressed":
if event.direction == "up":
time()
sense.clear()