Skip to content

Instantly share code, notes, and snippets.

@EmperorPenguin18
Created May 10, 2021 23:13
Show Gist options
  • Save EmperorPenguin18/5ffc9d6af49a60e5e1f2bb83ebbd45c0 to your computer and use it in GitHub Desktop.
Save EmperorPenguin18/5ffc9d6af49a60e5e1f2bb83ebbd45c0 to your computer and use it in GitHub Desktop.
Control a RPI vehicle with one letter commands
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
MOTOR1 = 14
MOTOR2 = 18
MOTOR3 = 24
MOTOR4 = 12
GPIO.setup(MOTOR1, GPIO.OUT)
GPIO.setup(MOTOR2, GPIO.OUT)
GPIO.setup(MOTOR3, GPIO.OUT)
GPIO.setup(MOTOR4, GPIO.OUT)
while True:
inputString = raw_input()
if inputString == "w":
GPIO.output(MOTOR1, True)
GPIO.output(MOTOR2, True)
GPIO.output(MOTOR3, True)
GPIO.output(MOTOR4, True)
elif inputString == "s":
GPIO.output(MOTOR1, False)
GPIO.output(MOTOR2, False)
GPIO.output(MOTOR3, False)
GPIO.output(MOTOR4, False)
elif inputString == "a":
GPIO.output(MOTOR1, False)
GPIO.output(MOTOR2, True)
GPIO.output(MOTOR3, False)
GPIO.output(MOTOR4, True)
elif inputString == "d":
GPIO.output(MOTOR1, True)
GPIO.output(MOTOR2, False)
GPIO.output(MOTOR3, True)
GPIO.output(MOTOR4, False)
elif inputString == "exit":
break
else:
print("I don't understand that command")
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment