Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. from time import sleep
  3. import readchar
  4.  
  5.  
  6. GPIO.setmode(GPIO.BOARD)
  7.  
  8. GPIO.setup(3, GPIO.OUT) #reverse
  9. GPIO.setup(5, GPIO.OUT) #forward
  10. GPIO.setup(8, GPIO.OUT) #left
  11. GPIO.setup(10, GPIO.OUT) #right
  12.  
  13.  
  14.  
  15. print("steer with w,a,d")
  16. print("forward r, reverse f")
  17.  
  18. while True:
  19.  
  20. key=readchar.readkey()
  21.  
  22. if key == "r":
  23. GPIO.output(5, GPIO.HIGH)
  24. sleep(1)
  25. GPIO.output(5, GPIO.LOW)
  26.  
  27. elif key == "f":
  28. GPIO.output(3, GPIO.HIGH)
  29. sleep(1)
  30. GPIO.output(3, GPIO.LOW)
  31.  
  32. elif key == "a":
  33. GPIO.output(10, GPIO.LOW)
  34.  
  35. GPIO.output(8, GPIO.HIGH)
  36.  
  37.  
  38. elif key == "d":
  39. GPIO.output(8, GPIO.LOW)
  40.  
  41. GPIO.output(10, GPIO.HIGH)
  42.  
  43.  
  44. elif key == "w":
  45. GPIO.output(8, GPIO.LOW)
  46. GPIO.output(10, GPIO.LOW)
  47.  
  48. elif key == "z":
  49. GPIO.cleanup()
  50. print("Motors on safe, exiting.")
  51. sleep(1)
  52. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement