Last active
February 28, 2017 10:46
-
-
Save ethanshine1234/9c066472d1c6037b7a0e77c68f28ddd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
def auto(): | |
GPIO.setmode(BCM) | |
GPIO.setup(11, GPIO.IN) | |
GPIO.setup(3, GPIO.OUT) | |
while True: | |
i=GPIO.input(11) | |
if i==0: | |
elif i==1: | |
GPIO.output(13, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(13, GPIO.LOW) | |
sleep(1) | |
GPIO.output(18, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(18, GPIO.LOW) | |
def manual(): | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(24, GPIO.OUT) | |
GPIO.setup(23, GPIO.OUT) | |
GPIO.setup(27, GPIO.OUT) | |
GPIO.setup(17, GPIO.OUT) | |
while True: | |
key=input("Type to control. WASD is what we'll use.") | |
if key == "w": #forward | |
GPIO.output(11, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(11, GPIO.LOW) | |
elif key == "s": #reverse | |
GPIO.output(13, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(13, GPIO.LOW) | |
elif key == "a": #steers left | |
GPIO.output(16, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(16, GPIO.LOW) | |
elif key == "d": #steers right | |
GPIO.output(18, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(18, GPIO.LOW) | |
elif key == "x": #quits the program | |
GPIO.cleanup() | |
print("Motors on safe, exiting.") | |
sleep(1) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment