烽火社区

标题: 【NUCLEO-F767ZI】用PWM控制LED亮度 [打印本页]

作者: pipixilie    时间: 2016-8-5 12:54 PM
标题: 【NUCLEO-F767ZI】用PWM控制LED亮度
在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)






欢迎光临 烽火社区 (https://bbs.cnecport.com/) Powered by Discuz! X3.2