python – Turning on LEDs by interrupt using a button with Raspberry Pi Pico H

from machine import Pin
interrupt_flag=0
counter=0
buton_1= Pin(5, Pin.IN, Pin.PULL_UP)
buton_2= Pin(6, Pin.IN, Pin.PULL_UP)
led= Pin("LED", Pin.OUT)

def callback(buton_1):
    global interrupt_flag
    interrupt_flag=1
    
buton_1.irq(trigger= Pin.IRQ_FALLING, handler=callback)

def callback2(buton_2):
    interrupt_flag=1
  
buton_2.irq(trigger= Pin.IRQ_FALLING, handler=callback2)
    
while True:
    counter+=1
    
    if interrupt_flag is 1 and counter==3:
        interrupt_flag=0
        led.toggle()
        interrupt_flag=1
    elif interrupt_flag is 1 and counter==5:
        interrupt_flag=0
        led.toggle()
        interrupt_flag=1
    elif interrupt_flag is 1 and  (buton_1 and buton_2) ==1:
         interrupt_flag=0
         led.toggle()

I can’t this. What I want to do is literally turn on and off the LED according to the number of cuts. I’m trying to do this with button control.

how can I do that

Read more here: Source link