logo

openmv 驱动 mg995的一些问题?

2021-04-09 22:52
4
_4ukf
import pyb,time
from pyb import Pin, Timer
p = Pin('P5')                         #Pin5 是定时器 2 通道 4
tim = Timer(2, freq=50)               #配置定时器 4 频率
ch = tim.channel(4, Timer.PWM, pin=p) #配置定时器通道 1
while (True):
    ch.pulse_width_percent(5)         #配置通道占空比
    time.sleep(1000)
    ch.pulse_width_percent(7.5) 	  #配置通道占空比
    time.sleep(1000)

在csdn上找的代码,发现占空比不能调为浮点数。编译会报错 cant convert float to int,不知如何是好。

2021-04-13 00:09
I
网红小智智 星瞳科技

ch.pulse_width_percent(7)

那就不用小数了呗。