import time
from machine import Pin,Timer
# setup
led = Pin(26)
led.init(Pin.OUT) #init call class
led.off()
# led.on() ac=0 none i in system
#if led off when ac=1 have i in sys
ac = 1
#built fn

def tim_isr(t):
    global ac
    ac = 1

#รับค่าจากปุ่มถ้า ac==1สลับtoggle
def button_isr(pin):
    global ac
    if (ac==1):
        ac = 0
        led.toggle() #ช่วงสลับค่าstate print
        print("toggle")
        tim = Timer(period=100,mode=Timer.ONE_SHOT,callback=tim_isr)
#ค่าperiodมากจะทำให้มีความแม่นยำในการจับdebounceมากทำให้เสถียรในการรับค่าปุ่ม ตอบสนองการติดดับปุ่มได้
#periodน้อยทำให้ดีเบาท์ในการจับสัญญาณกดปุ่มจะตอบสนองทันทีเมื่อสถานะเปลี่ยนเลยจำเป็นต้องกดปุ่มค้าง

pin = Pin(27,mode=Pin.IN,pull=Pin.PULL_UP)
pin.irq(trigger=Pin.IRQ_FALLING,handler=button_isr)
#irq check interup push butt but_isr
#triggle print เสร็จcall back ac release out loop but led.off value=0
follow = time.ticks_ms()
while True:
    now = time.ticks_ms()
    if (time.ticks_diff(now,follow)>100):
        print(led.value())
        follow = time.ticks_ms()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT