pimoroni-pico/micropython/examples/plasma2040/rgb-led-and-buttons.py

26 lines
698 B
Python
Raw Normal View History

import time
2021-08-19 15:50:16 +01:00
# Import plasma2040
from plasma import plasma2040
# Import helpers for RGB LEDs and Buttons
from pimoroni import RGBLED, Button
2021-08-19 15:50:16 +01:00
led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)
led.set_rgb(0, 0, 0)
2021-08-19 15:50:16 +01:00
user_sw = Button(plasma2040.USER_SW)
button_a = Button(plasma2040.BUTTON_A)
button_b = Button(plasma2040.BUTTON_B)
while True:
if user_sw.read():
print("Pressed User SW - {}".format(time.ticks_ms()))
led.set_rgb(255, 0, 0)
if button_a.read():
print("Pressed A - {}".format(time.ticks_ms()))
led.set_rgb(0, 255, 0)
if button_b.read():
print("Pressed B - {}".format(time.ticks_ms()))
led.set_rgb(0, 0, 255)