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

  • shaoziyang
  • LV5工程师
  • |      2016-08-05 12:54:43
  • 浏览量 927
  • 回复:1
在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)
  • 0
  • 收藏
  • 举报
  • 分享
我来回复

登录后可评论,请 登录注册

所有回答 数量:1
Rhdh 2016-08-08
马克。。
0   回复
举报
发布
x
收藏成功!点击 我的收藏 查看收藏的全部帖子