烽火社区
标题:
【STM32L476 Nucleo】使用按键控制LED的频率
[打印本页]
作者:
开心123
时间:
2016-5-15 01:25 AM
标题:
【STM32L476 Nucleo】使用按键控制LED的频率
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)
复制代码
欢迎光临 烽火社区 (https://bbs.cnecport.com/)
Powered by Discuz! X3.2