Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pybricks.pupdevices import Motor, Remote, Light
- from pybricks.parameters import Port, Direction, Stop, Button
- from pybricks.tools import wait
- # Initialize the motors.
- steer = Motor(Port.B)
- light = Light(Port.C)
- front = Motor(Port.A, Direction.COUNTERCLOCKWISE)
- front.control.limits(acceleration=500)
- steer.control.limits(acceleration=500)
- remote = Remote()
- left_end = steer.run_until_stalled(-200, then=Stop.HOLD)
- right_end = steer.run_until_stalled(200, then=Stop.HOLD)
- steer.reset_angle((right_end - left_end) / 2)
- steer.run_target(speed=200, target_angle=0, wait=False)
- hold = False
- while True:
- pressed = remote.buttons.pressed()
- steer_angle = 0
- if Button.RIGHT_MINUS in pressed:
- steer_angle -= 75
- if Button.RIGHT_PLUS in pressed:
- steer_angle += 75
- if Button.RIGHT in pressed:
- steer_angle = 0
- steer.run_target(500, steer_angle, wait=False)
- drive_speed = 0
- if Button.LEFT_PLUS in pressed:
- drive_speed += 5000
- if Button.LEFT_MINUS in pressed:
- drive_speed -= 5000
- if Button.LEFT in pressed:
- wait(500)
- if hold == True:
- hold = False
- else:
- hold = True
- bright = front.speed() / 15
- if hold == True:
- front.control.limits(acceleration=5000)
- front.run(750)
- light.on(bright)
- else:
- front.control.limits(acceleration=500)
- front.run(drive_speed)
- light.on(bright)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement