Last active
March 12, 2017 18:46
-
-
Save ethanshine1234/470a61959ed077b8fc9dce0f02312cf8 to your computer and use it in GitHub Desktop.
STJLOL-ES-homework
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
""" | |
This program is supposed to be able to allow you to choose if | |
you want to manualy control it or let it control itself. | |
I hope that this program will blow your mind. | |
""" | |
import RPi.GPIO as GPIO | |
from time import sleep | |
def auto(): | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(24, GPIO.OUT) | |
GPIO.setup(23, GPIO.OUT) | |
GPIO.setup(27, GPIO.OUT) | |
GPIO.setup(17, GPIO.OUT) | |
GPIO.setup(13, GPIO.IN) | |
while True: | |
i=GPIO.input(13) | |
GPIO.output(23, GPIO.HIGH) | |
GPIO.output(17, GPIO.HIGH) | |
if i==0: | |
print("CLEAR") | |
elif i==1: | |
GPIO.output(23, GPIO.LOW) | |
GPIO.output(17, GPIO.LOW) | |
GPIO.output(24, GPIO.HIGH) | |
GPIO.output(27, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(27, GPIO.LOW) | |
GPIO.output(27, GPIO.LOW) | |
sleep(1) | |
number=random.random() | |
number=10*number | |
if number > 5: | |
GPIO.output(17, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(17, GPIO.LOW) | |
elif number < 5: | |
GPIO.output(23, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(23, 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. X will quit the program") | |
if key == "w": #forward | |
GPIO.output(23, GPIO.HIGH) | |
GPIO.output(17, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(23, GPIO.LOW) | |
GPIO.output(17, GPIO.LOW) | |
elif key == "s": #reverse | |
GPIO.output(24, GPIO.HIGH) | |
GPIO.output(27, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(24, GPIO.LOW) | |
GPIO.OUTPUT(27, GPIO.LOW) | |
elif key == "a": #steers left | |
GPIO.output(17, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(17, GPIO.LOW) | |
elif key == "d": #steers right | |
GPIO.output(23, GPIO.HIGH) | |
sleep(1) | |
GPIO.output(23, GPIO.LOW) | |
elif key == "x": #quits the program | |
GPIO.cleanup() | |
print("Motors on safe, exiting.") | |
sleep(1) | |
break | |
print("Welcome SUPERUSER") | |
print("Manual Control") | |
print("Autonomous Control") | |
do=input("Which one") | |
if do == "manual control": | |
print("MANUAL OVERRIDE") | |
manual() | |
elif do == "Manual Control": | |
print("MANUAL OVERRIDE") | |
manual() | |
elif do == "autonomous control": | |
auto() | |
elif do == "Autonomous Control": | |
auto() | |
else: | |
print("You are not ready") | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment