from machine import Pin
import time
led1=Pin(23,Pin.OUT)
led2=Pin(22,Pin.OUT)
led3=Pin(21,Pin.OUT)
led4=Pin(19,Pin.OUT)
key1=Pin(25,Pin.IN,Pin.PULL_UP)
key2=Pin(26,Pin.IN,Pin.PULL_UP)
key3=Pin(27,Pin.IN,Pin.PULL_UP)
key4=Pin(14,Pin.IN,Pin.PULL_UP)
r,g,m,n=0,0,0,0
k_en=1
def key1_irq(key1):
global r,k_en
if k_en==1 and key1.value()==0:
time.sleep_ms(50)
k_en=0
if key1.value()==0:
r=not r
led1.value(r)
elif key1.value()==1:
time.sleep_ms(50)
k_en=1
def key2_irq(key2):
global g,k_en
if k_en==1 and key2.value()==0:
time.sleep_ms(50)
k_en=0
if key2.value()==0:
g=not g
led2.value(g)
elif key2.value()==1:
time.sleep_ms(50)
k_en=1
def key3_irq(key3):
global m,k_en
if k_en==1 and key3.value()==0:
time.sleep_ms(50)
k_en=0
if key3.value()==0:
m=not m
led3.value(m)
elif key3.value()==1:
time.sleep_ms(50)
k_en=1
def key4_irq(key4):
global n,k_en
if k_en==1 and key4.value()==0:
time.sleep_ms(50)
k_en=0
if key4.value()==0:
n=not n
led4.value(n)
elif key4.value()==1:
time.sleep_ms(50)
k_en=1
led1.value(1)
led2.value(1)
led3.value(1)
led4.value(1)
key1.irq(key1_irq,Pin.IRQ_FALLING)
key2.irq(key2_irq,Pin.IRQ_FALLING)
key3.irq(key3_irq,Pin.IRQ_FALLING)
key4.irq(key4_irq,Pin.IRQ_FALLING)
while True:
pass