def moveJoystick(x, y): joystick.clear() joystick.goto(x, y) joystick.pendown() joystick.dot(30, "blue") joystick.penup() print("Joystick position: x =", x, ", y =", y) # Scale the joystick coordinates to the range [-255, 255] scaled_x = int(x * 255 / screen.window_width()) scaled_y = int(y * 255 / screen.window_height()) # Send the joystick coordinates to the Arduino via serial ser.write(f"{scaled_x},{scaled_y}\n".encode())
# Bind the joystick movement function to the screen
screen.onscreenclick(moveJoystick)
# Open a serial connection to the Arduino via the HC-05 module