from machine import I2C,Pin import time p13 = Pin(13, Pin.IN) # 构建人体外对象 led = Pin(2, Pin.OUT) # 构建led对象,GPIO2 输出 def fun(*args): #检测到人,led亮灯 print("1") led.on() time.sleep_ms(500) led.off() p13.irq(fun, Pin.IRQ_RISING) # 定义中断,上升触发