Ex3 - Button controlled LED
https://gpiozero.readthedocs.io/en/stable/recipes.html#button-controlled-led
任務 1

另開新檔。以下程式碼,在按下 Button
時打開 LED
from gpiozero import LED, Button
from signal import pause
button = Button(5)
led = LED(6)
button.when_pressed = led.toggle
pause()
任務 2
另開新檔, button_led_2.py
。參考 Ex2 - Button 中的任務4,修改以上程式碼,讓你可以在當按下按扭時開啟/閃動 LED
,放手時會關閉 LED
。以下是你可能需要用的資料連結。
Last updated
Was this helpful?