代码意义如下:
while (base.buttons[3].read()==0)://定义一个循环,直到btn3按下结束
if (base.buttons[0].read()==1)://btn0按下改变led颜色
15
color = (color+1) % 8
for led in rgbled_position:
base.rgbleds[led].write(color)
base.rgbleds[led].write(color)
sleep(Delay1)
elif (base.buttons[1].read()==1)://按下btn1
for led in base.leds://一个循环用于实现流水灯
led.off()
sleep(Delay2)
for led in base.leds:
led.toggle()
sleep(Delay2)
elif (base.buttons[2].read()==1)://实现反向的流水灯
for led in reversed(base.leds):
led.off()
sleep(Delay2)
for led in reversed(base.leds):
led.toggle()
sleep(Delay2)
print('End of this demo ...')
for led in base.leds://关闭led灯
led.off()
for led in rgbled_position:
base.rgbleds[led].off()
输入代码然后点击运行则可行实现按下btn0改变led4和5的颜色,按下btn1是从右到左的流水灯,按下btn2是从左到右的流水灯,btn4退出程序,效果如下:
`