Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6814

Python • Making a flight simulator joystick

$
0
0
How would I make the mouse recenter to the middle of my main desktop when the joystick isn't being moved left or right.

Code:

import timeimport boardimport analogioimport usb_hidfrom adafruit_hid.mouse import Mouse# Joystick axesx_axis = analogio.AnalogIn(board.A0)y_axis = analogio.AnalogIn(board.A1)mouse = Mouse(usb_hid.devices)# Sensitivity and deadzoneDEADZONE = 1000SCALE = 5000# Read axisdef read_axis(pin):    raw = pin.value    centered = raw - 32768    if abs(centered) < DEADZONE:        return 0    return int(centered / SCALE)# Main loopwhile True:    dx = read_axis(x_axis)    dy = read_axis(y_axis)    mouse.move(dx, -dy)  # Invert Y for natural feel    time.sleep(0.01)

Statistics: Posted by FlightSimulatorGuy — Thu Oct 02, 2025 10:45 pm — Replies 0 — Views 15



Viewing all articles
Browse latest Browse all 6814

Trending Articles