Merge pull request #803 from pimoroni/examples/tiny2040

Tiny 2040: add button/LED example
pull/817/head
Hel Gibbons 2023-07-21 13:33:07 +01:00 zatwierdzone przez GitHub
commit 03232bbeb5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
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)