-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProject 15.py
69 lines (57 loc) · 1.6 KB
/
Project 15.py
1
import osimport sysimport termiosimport ttyimport Adafruit_BBIO.GPIO as GPIOimport timeimport Adafruit_BBIO.PWM as PWMGPIO.setup("P9_14", GPIO.OUT) GPIO.setup("P8_19", GPIO.OUT) GPIO.setup("P9_13", GPIO.OUT) #motor1GPIO.setup("P9_15", GPIO.OUT)GPIO.setup("P8_10", GPIO.OUT) #motor2GPIO.setup("P8_12", GPIO.OUT)def getKey(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ICANON & ~termios.ECHO new[6][termios.VMIN] = 1 new[6][termios.VTIME] = 0 termios.tcsetattr(fd, termios.TCSANOW, new) key = None try: key = os.read(fd, 3) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old) return keywhile 1: x = str(getKey()) if x == "w": PWM.start("P9_14", 10, 2000, 1)PWM.start("P8_19", 10, 2000, 1) GPIO.output("P9_13", GPIO.HIGH) GPIO.output("P9_15", GPIO.LOW) GPIO.output("P8_10", GPIO.HIGH) GPIO.output("P8_12", GPIO.LOW) elif x == "s": PWM.start("P9_14", 10, 2000, 1) PWM.start("P8_19", 10, 2000, 1) GPIO.output("P9_13", GPIO.LOW) GPIO.output("P9_15", GPIO.HIGH) GPIO.output("P8_10", GPIO.LOW) GPIO.output("P8_12", GPIO.HIGH) elif x == "a": PWM.start("P9_14", 10, 2000, 0) PWM.start("P8_19", 10, 2000, 1) GPIO.output("P8_10", GPIO.HIGH) GPIO.output("P8_12", GPIO.LOW) elif x == "d": PWM.start("P9_14", 10, 2000, 1) PWM.start("P8_19", 10, 2000, 0) GPIO.output("P9_13", GPIO.HIGH)GPIO.output("P9_15", GPIO.LOW) else: PWM.stop("P9_14") PWM.stop("P8_19") PWM.cleanup()