From c696cd5e2d37d7f989e5d51199f96c5b958495b5 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Fri, 21 Jul 2023 13:03:44 +0100 Subject: [PATCH] Tiny 2040: add button/LED example --- micropython/examples/tiny2040/button_test.py | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 micropython/examples/tiny2040/button_test.py diff --git a/micropython/examples/tiny2040/button_test.py b/micropython/examples/tiny2040/button_test.py new file mode 100644 index 00000000..402d43e8 --- /dev/null +++ b/micropython/examples/tiny2040/button_test.py @@ -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)