logo

如何编辑代码,编出一段函数(变量x和y)使pwm的占空比随变量变化?下图为自己编写的程序,报错了

2021-01-21 12:43
K
x31y
# PWM 控制例子
#
# 这个例子展示了如何使用OpenMV的PWM

import time
from pyb import Pin, Timer
int x
int y
x=0
while(x<39):
def ads(x)
    result=x/2+1
    return result
y=ads(x)

tim = Timer(4, freq=1000)
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=x)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=y)
x=x+1
while (True):
    time.sleep_ms(1000)
2021-01-25 18:46
I
网红小智智 星瞳科技
import time
from pyb import Pin, Timer

tim = Timer(4, freq=1000) # Frequency in Hz
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=0)

while (True):
    x = 50
    ch1.pulse_width_percent(x)