from gpiozero import Robot from bluedot import BlueDot from signal import pause def pos_to_values(x, y): left = y if x > 0 else y + x right = y if x < 0 else y - x return (clamped(left), clamped(right)) def clamped(v): return max(-1, min(1, v)) def drive(): while True: if bd.is_pressed: x, y = bd.position.x, bd.position.y yield pos_to_values(x, y) else: yield (0, 0) robot = Robot(left=(4, 14), right=(17, 18)) bd = BlueDot() robot.source = drive() pause()