from pyb import Pin #引入引脚
from pyb import ExtInt #引入中断
callbackup = lambda e: print("up") #定义按键回调
callbackdown = lambda e: print("down") #定义按键回调
callbackleft = lambda e: print("left") #定义按键回调
callbackright = lambda e: print("right") #定义按键回调
callbackok = lambda e: print("ok") #定义按键回调
ext = ExtInt(Pin('W10'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackup) #定义按键回调
ext = ExtInt(Pin('W11'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackdown) #定义按键回调
ext = ExtInt(Pin('W12'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackleft) #定义按键回调
ext = ExtInt(Pin('W13'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackright)#定义按键回调
ext = ExtInt(Pin('W14'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackok) #定义按键回调
本资料转载自openioe
及互联网
原版的按键没有进行去抖动处理,pyboardCN V2的按键已经加了。