[cc lang=”python”]
from gpiozero import LED, Button
from time import sleep
led = LED(17)
button = Button(2)
while True:
button.wait_for_press()#等待按键按下
led.toggle() #LED状态翻转
button.wait_for_release() #等待按键释放
[/cc]
转载请注明:徐自远的乱七八糟小站 » 测试1答案:按键翻转LED