中文注释from pyb import PinLEDExtIntdelay led1 = LED1 led2 = LED2 led3 = LED3 led4 = LED4 led1on led2off led3off led4off led = led1 led2 led3 led4 index = 3 def k1_isr global index ledindexoff index = i
中文注释
导入需要的模块
from pyb import Pin, LED, ExtInt, delay
创建LED对象
led1 = LED(1) led2 = LED(2) led3 = LED(3) led4 = LED(4)
设置初始状态,其中led1亮,led2、led3和led4灭
led1.on() led2.off() led3.off() led4.off()
将led对象存入列表中
led = [led1, led2, led3, led4]
设置初始索引为3
index = 3
定义按键中断回调函数
def k1_isr(): global index led[index].off() index = (index + 1) % len(led) led[index].on()
创建按键中断对象
callback = lambda e: k1_isr() ext = ExtInt(Pin('K1'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callback)
循环执行
while True: delay(500
原文地址: http://www.cveoy.top/t/topic/hB24 著作权归作者所有。请勿转载和采集!