我正在尝试使用 BBC:Microbit 在按下按钮 a 时在其 LED 上显示 1 秒钟的闪光。这可行,但我希望它在等待按下按钮时显示动画(待机)。下面的代码仅显示待机图像,按下按钮 a 时不运行其余代码。我做错了什么?谢谢。
from microbit import *
standby1 = Image("00000:"
"00000:"
"90000:"
"00000:"
"00000")
standby2 = Image("00000:"
"00000:"
"09000:"
"00000:"
"00000")
standby3 = Image("00000:"
"00000:"
"00900:"
"00000:"
"00000")
standby4 = Image("00000:"
"00000:"
"00090:"
"00000:"
"00000")
standby5 = Image("00000:"
"00000:"
"00009:"
"00000:"
"00000")
all_leds_on = Image("99999:"
"99999:"
"99999:"
"99999:"
"99999")
standby = [standby1, standby2, standby3, standby4, standby5, standby4, standby3, standby2]
display.show(standby, loop=True, delay=100)#Show standby LEDS on a loop
#Wait for button a to be pressed
while True:
if button_a.was_pressed():
sleep(1000)#pause program for 1 second
display.show(all_leds_on) #Turn on LEDS for 1 second
sleep(1000)#pause program for 1 second
display.clear()