Tiny 2040: add button/LED example

pull/803/head
helgibbons 2023-07-21 13:03:44 +01:00
rodzic 25237c54ce
commit c696cd5e2d
1 zmienionych plików z 28 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,28 @@
# Simple demo of how to use the RGB LED and read the button on Tiny 2040.
from pimoroni import Button, RGBLED
import time
led = RGBLED(18, 19, 20)
button_boot = Button(23)
# start with the LED off
led.set_rgb(0, 0, 0)
# flash the LED red, green and blue
led.set_rgb(255, 0, 0)
time.sleep(0.5)
led.set_rgb(0, 255, 0)
time.sleep(0.5)
led.set_rgb(0, 0, 255)
time.sleep(0.5)
print("Press the button!")
while True:
# flash the LED white when the button is pressed
if button_boot.read():
print("Button pressed!")
led.set_rgb(255, 255, 255)
time.sleep(0.5)
led.set_rgb(0, 0, 0)