import machine as mc
import utime
#Define global variables
# Define the GPIO pins connected to the RGB LED
RED_PIN = mc.Pin(15, mc.Pin.OUT)
GREEN_PIN = mc.Pin(14, mc.Pin.OUT)
BLUE_PIN = mc.Pin(13, mc.Pin.OUT)
#Define GPIO in button
push_bt = mc.Pin(16, mc.Pin.IN, mc.Pin.PULL_UP)
#base values
button_pressed = False
#check whether button pressed
def wait_pin_change(pin):
# wait for pin to change value
# it needs to be stable for a continuous 20ms
cur_value = pin.value()
active = 0
while active < 5:
if pin.value() != cur_value:
active += 1
else:
active = 0
sleep_ms(1)
# Interrupt Service Routine for Button Pressed Events - with no debounce
def button_pressed(change):
global button_pressed
button_pressed = True
# here is how we associate the falling value on the input pin with the callback function
push_bt.irq(handler=button_pressed, trigger=mc.Pin.IRQ_FALLING)
# Function to set the color of the RGB LED
def set_color(red, green, blue):
RED_PIN.value(red)
GREEN_PIN.value(green)
BLUE_PIN.value(blue)
# Main loop to cycle through colors
while True:
if (button_pressed == True):
print("button_pressed")
wait_pin_change(push_bt)
button_pressed = False
if (led.value() == 1):
set_color(255, 0, 0) # Red
utime.sleep(1)
set_color(0, 255, 0) # Green
utime.sleep(1)
set_color(0, 0, 255) # Blue
utime.sleep(1)
print("Done changing")
else:
set_color(0, 0, 0)
print("Im off")
sleep(1)
print("working")
sleep(0.2)
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r