Hi,
I am teacher in France and I need some help about programming robot in python.
I want to drive a robot “Smart Car” from Elecfreaks , via micropython (with mu editor).
It works fine with MakeCode blocks (with specific blocks for motorbit) but I can’t do it in python.
Here is my code in python :
from microbit import *
directD = pin8 # right dir (forward = 0, reverse = 1)
moteurD = pin1 # rigth motor (PWM)
directG = pin12 # left dir (forward = 0, reverse = 1)
moteurG = pin2 # left motor (PWM)
display.off # désactivation des 25 leds
def avancer(vitesse):
directD.write_digital(0)
directG.write_digital(0)
moteurD.write_analog(vitesse)
moteurG.write_analog(vitesse)
def reculer(vitesse):
directD.write_digital(1)
directG.write_digital(1)
moteurD.write_analog(1023-vitesse)
moteurG.write_analog(1023-vitesse)
for k in range(2):
avancer(1000)
sleep(1000)
reculer(1000)
sleep(1000)
Yes it moves but instead of repeating twice “go forward + wait 1sec + go backward +wait for 1sec”
it does that : “move right + wait + move right + wait”
I verified the connection : the pins are correctly used. I did not weld the wires on the engines: I just pinched them. But this is probably not the problem because I was able to run the program written with the blocks :