Untitled
unknown
plain_text
9 months ago
1.3 kB
9
Indexable
import serial
import time
import keyboard # Install with `pip install keyboard`
# Open Serial Port (update port if needed)
arduino = serial.Serial('/dev/serial0', 9600, timeout=1)
time.sleep(2) # Wait for connection
print("Use WASD to move, T/G to control throttle, X to stop.")
while True:
if keyboard.is_pressed("w"):
arduino.write(b'w')
print("Moving Forward")
elif keyboard.is_pressed("s"):
arduino.write(b's')
print("Moving Backward")
elif keyboard.is_pressed("a"):
arduino.write(b'a')
print("Moving Left")
elif keyboard.is_pressed("d"):
arduino.write(b'd')
print("Moving Right")
elif keyboard.is_pressed("q"):
arduino.write(b'q')
print("Rotating Left")
elif keyboard.is_pressed("e"):
arduino.write(b'e')
print("Rotating Right")
elif keyboard.is_pressed("t"):
arduino.write(b't')
print("Increasing Throttle")
elif keyboard.is_pressed("g"):
arduino.write(b'g')
print("Decreasing Throttle")
elif keyboard.is_pressed("x"):
arduino.write(b'x')
print("Emergency Stop")
time.sleep(0.1) # Avoid spamming the serial connection
Editor is loading...
Leave a Comment