Skip to content

Commit c696cd5

Browse files
committed
Tiny 2040: add button/LED example
1 parent 25237c5 commit c696cd5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Simple demo of how to use the RGB LED and read the button on Tiny 2040.
2+
3+
from pimoroni import Button, RGBLED
4+
import time
5+
6+
led = RGBLED(18, 19, 20)
7+
button_boot = Button(23)
8+
9+
# start with the LED off
10+
led.set_rgb(0, 0, 0)
11+
12+
# flash the LED red, green and blue
13+
led.set_rgb(255, 0, 0)
14+
time.sleep(0.5)
15+
led.set_rgb(0, 255, 0)
16+
time.sleep(0.5)
17+
led.set_rgb(0, 0, 255)
18+
time.sleep(0.5)
19+
20+
print("Press the button!")
21+
22+
while True:
23+
# flash the LED white when the button is pressed
24+
if button_boot.read():
25+
print("Button pressed!")
26+
led.set_rgb(255, 255, 255)
27+
time.sleep(0.5)
28+
led.set_rgb(0, 0, 0)

0 commit comments

Comments
 (0)