我正在编写一个 python 脚本,它将使用 cwiid 库通过 Wiimote 控制 LED。该程序识别 wiimote 并能够启动循环,但是当用户按遥控器上的“B”时它不会让我停止循环。这是相关代码,如果需要,我可以提供脚本的其余部分。谢谢。
buttons = wii.state['buttons']
...
if (buttons & cwiid.BTN_A):
print 'Button A pressed'
print 'Press B to cancel loop'
keepRunning = True
while keepRunning:
blink(32)#5v green
blink(38)#5v yellow
blink(36)#5v blue
blink(40)#5v red
blink(37)#3v3 green
blink(35)#3v3 yellow
blink(33)#3v3 blue
blink(31)#3v3 red
if (buttons & cwiid.BTN_B):
keepRunning = False
time.sleep(button_delay)
这是每个斯图尔特答案的固定循环
if (buttons & cwiid.BTN_A):
print 'Button A pressed'
print 'Press B to cancel loop'
keepRunning = True
while keepRunning:
blink(32)#5v green
blink(38)#5v yellow
blink(36)#5v blue
blink(40)#5v red
blink(37)#3v3 green
blink(35)#3v3 yellow
blink(33)#3v3 blue
blink(31)#3v3 red
buttons = wii.state['buttons']#added in this line
if (buttons & cwiid.BTN_B):
keepRunning = False
time.sleep(button_delay)