Nucleo开发板的默认开机程序是使用按键控制LED的频率,下面使用MicroPython实现同样的功能。
from pyb import Pin, Timer
tm = Timer(2, freq=1)
led = tm.channel(1, Timer.PWM, pin=Pin.cpu.A5)
led.pulse_width_percent(50)
f = 1
def sw_isr():
global f
f=(f+5)%10
tm.freq(f)
led.pulse_width_percent(50)
sw = pyb.Switch()
sw.callback(sw_isr)
Nucleo开发板的默认开机程序是使用按键控制LED的频率,下面使用MicroPython实现同样的功能。
from pyb import Pin, Timer
tm = Timer(2, freq=1)
led = tm.channel(1, Timer.PWM, pin=Pin.cpu.A5)
led.pulse_width_percent(50)
f = 1
def sw_isr():
global f
f=(f+5)%10
tm.freq(f)
led.pulse_width_percent(50)
sw = pyb.Switch()
sw.callback(sw_isr)