IRQ:插件中断
Python代码显示插件中断函数Arduino主控板连接Windows或Linux计算机,按钮模块连接主控板D8插件
#-*编码:UTF-8-*-#实验效果:pin中断函数测试#连接:Windows或Linux计算机连接Arduino主控制板,主控制板D8连接到按钮模块导入时间If no port number is entered, automatic detection will be performed # Board("uno", "COM36").begin() # Initialization with specified port on Windows # Board("uno", "/dev/ttyACM0").begin() # Initialization with specified port on Linux # Board("uno", "/dev/cu.usbmodem14101").begin() # Initialization with specified port on Mac btn = Pin(Pin.D8, Pin.IN) def btn_rising_handler(pin): # Interrupt event callback function print("\n--rising---") print("pin = ", pin) def btn_falling_handler(pin): # Interrupt event callback function print("\n--falling---") print("pin = ", pin) def btn_both_handler(pin): # Interrupt event callback function print("\n--both---") print("pin = ", pin) btn.irq(trigger=Pin.IRQ_FALLING, handler=btn_falling_handler) # Set the interrupt mode to trigger on falling edge # btn.irq(trigger=Pin.IRQ_RISING, handler=btn_rising_handler) # Set the interrupt mode to trigger on rising edge, and callback function # btn.irq(trigger=Pin.IRQ_RISING+Pin.IRQ_FALLING, handler=btn_both_handler) # Set the interrupt mode to trigger when the level changes while True: time.sleep(1) # Keep the program running continuously