from pyb import Pin, Timer
pwma = Pin('P7')
pwmb = Pin('P8')
inverse_left=False #change it to True to inverse left wheel
inverse_right=False #change it to True to inverse right wheel
tim = Timer(4, freq=50)
ch1 = tim.channel(1, Timer.PWM, pin=pwma)
ch2 = tim.channel(2, Timer.PWM, pin=pwmb)
ch1.pulse_width_percent(7.5)
ch2.pulse_width_percent(7.5)
def run(left_speed, right_speed):
if inverse_left==True:
left_speed=(-left_speed)
if inverse_right==True:
right_speed=(-right_speed)
if left_speed > 0:
ch1.pulse_width_percent(abs(left_speed))
if right_speed > 0:
ch2.pulse_width_percent(abs(right_speed))