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

[复制链接]
1009|2
 楼主| shaoziyang 发表于 2016-8-5 11:53 | 显示全部楼层 |阅读模式

在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)
mmuuss586 发表于 2016-8-5 13:03 | 显示全部楼层

谢谢分享;
Larm1 发表于 2016-8-5 14:40 | 显示全部楼层
好东西,谢谢楼主分享...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:https://www.micropython.org.cn/

30

主题

313

帖子

6

粉丝
快速回复 在线客服 返回列表 返回顶部