from microbit import * #motors pinMotorLeft = pin12 pinMotorRight = pin13 pinMotorLeft.set_analog_period(10) pinMotorRight.set_analog_period(10) #line tracking sensor pinGroundLeft = pin0 pinGroundRight = pin1 def clip(v,vmin,vmax): if v > vmax: v = vmax if v < vmin: v = vmin return v def setLeftSpeed(v):# v from -100 to 100 v = clip(v,-100,100) pinMotorLeft.write_analog(150+v) def setRightSpeed(v):# v from -100 to 100 v = clip(v,-100,100) pinMotorRight.write_analog(150-v) standBy = True while True: if button_a.was_pressed(): standBy = not(standBy) if standBy: setLeftSpeed(0) setRightSpeed(0) if not(standBy): #test line tracking sensors print((pinGroundLeft.read_analog(),pinGroundRight.read_analog())) # dark = 750, white = 50 if(pinGroundLeft.read_analog()>550): setLeftSpeed(-10) setRightSpeed(10) elif(pinGroundRight.read_analog()<250): setLeftSpeed(10) setRightSpeed(-10) else: setLeftSpeed(20) setRightSpeed(20) sleep(100)