查看: 2295|回复: 0
打印 上一主题 下一主题

【NUCLEO-F767ZI】用PWM控制LED亮度

[复制链接] qrcode

29

主题

29

帖子

89

积分

注册会员

Rank: 2

积分
89
楼主
跳转到指定楼层
发表于 2016-8-5 12:54 PM | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在MicroPython中用PWM控制LED的亮度,需要使用Timer和Pin两个模块

from pyb import Pin, Timer

# led1使用TIM1_CH2
tm1=Timer(1, freq=1000)
led1=tm1.channel(2, Timer.PWM, pin=Pin('B0'))

# 设置亮度(绿),0最亮,100最暗
led1.pulse_width_percent(0)
led1.pulse_width_percent(100)

# led2(兰)使用TIM4_CH2
tm4=Timer(4, freq=1000)
led2=tm4.channel(2, Timer.PWM, pin=Pin('B7'))

# 设置亮度,0最暗,100最亮
led2.pulse_width_percent(10)


# led3(红)使用TIM4_CH2N

tm8=Timer(8, freq=1000)
led3=tm8.channel(2, Timer.PWM, pin=Pin('B14'))

# 设置亮度,0最亮,100最暗
led3.pulse_width_percent(90)


#led3也可以使用TIM12_CH1
tm12=Timer(12, freq=1000)
led3=tm12.channel(1, Timer.PWM, pin=Pin('B14'))
led3.pulse_width_percent(0)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表