import serial
import pyvjoy
import time
# ==========================
# SETTINGS
# ==========================
COM_PORT = "COM7"
BAUDRATE = 115200
# ==========================
# CONNECT TO VJOY
# ==========================
j = pyvjoy.VJoyDevice(1)
# ==========================
# CONNECT TO ESP32
# ==========================
ser = serial.Serial(COM_PORT, BAUDRATE, timeout=1)
time.sleep(2)
print("Connected to ESP32")
print("Waiting for pedal data...")
# ==========================
# MAIN LOOP
# ==========================
while True:
try:
line = ser.readline().decode("utf-8").strip()
if not line:
continue
data = line.split(",")
if len(data) != 4:
continue
throttle = int(data[0])
brake = int(data[1])
button1 = int(data[2])
button2 = int(data[3])
throttle = max(0, min(65535, throttle))
brake = max(0, min(65535, brake))
# X Axis = Throttle
j.set_axis(pyvjoy.HID_USAGE_X, throttle)
# Y Axis = Brake
j.set_axis(pyvjoy.HID_USAGE_Y, brake)
# Buttons
j.set_button(1, button1)
j.set_button(2, button2)
except KeyboardInterrupt:
print("Stopped.")
break
except Exception as e:
print("Error:", e)
To embed this project on your website, copy the following code and paste it into your website's HTML: