Código: Selecionar todos
from pybricks.pupdevices import Motor, ColorDistanceSensor
from pybricks.hubs import CPlusHub
from pybricks.parameters import Port, Stop, Color
from pybricks.tools import wait
hub = CPlusHub()
sensor1 = ColorDistanceSensor(Port.A)
mR = Motor(Port.B)
mL = Motor(Port.D)
LETMEGETTHERE = 7500
ReflectionTHRESHOLD=35 # light sensor reflection read, percent
MoveDUTY = 70 # Duty Cycle, percent
TURN = 60
STEP = 5
wait(LETMEGETTHERE)
#start
while True:
if sensor1.reflection() < ReflectionTHRESHOLD:
hub.light.on(Color.RED)
mR.dc(MoveDUTY)
mL.dc(-MoveDUTY)
wait(STEP)
mR.dc(2*TURN)
mL.dc(0)
wait(STEP)
else:
hub.light.on(Color.GREEN)
mR.dc(MoveDUTY)
mL.dc(-MoveDUTY)
wait(STEP)
mR.dc(0)
mL.dc(-2*TURN)
wait(STEP)