Author: Not specified Language: python
Description: Not specified Timestamp: 2017-02-02 11:17:34 +0000
View raw paste Reply
  1. from RPi import GPIO as GPIO
  2. import time
  3.  
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setwarnings(False)
  6.  
  7. linksFwd = 8
  8. linksRev = 7
  9. rechtsFwd = 10
  10. rechtsRev = 9
  11.  
  12. REVS = 10
  13.  
  14. GPIO.setup(linksFwd, GPIO.OUT)
  15. GPIO.setup(linksRev, GPIO.OUT)
  16. GPIO.setup(rechtsFwd, GPIO.OUT)
  17. GPIO.setup(rechtsRev, GPIO.OUT)
  18.  
  19. lf = GPIO.PWM(linksFwd, REVS)
  20. rf = GPIO.PWM(rechtsFwd, REVS)
  21. rb = GPIO.PWM(rechtsRev, REVS)
  22. lb = GPIO.PWM(linksRev, REVS)
  23.  
  24. lf.start(0)
  25. rf.start(0)
  26. rb.start(0)
  27. lb.start(0)
  28.  
  29. '''
  30. Duty cycle korter -> langzamger
  31. '''
  32.  
  33. def init():
  34.     GPIO.output(linksFwd, 0)
  35.     GPIO.output(linksRev, 0)
  36.     GPIO.output(rechtsFwd, 0)
  37.     GPIO.output(rechtsRev, 0)
  38.  
  39.  
  40. def forward(dutyCycle):
  41.     lf.ChangeDutyCycle(dutyCycle)
  42.     rf.ChangeDutyCycle(dutyCycle)
  43.  
  44.  
  45. def backward(dutyCycle):
  46.     lb.ChangeDutyCycle(dutyCycle)
  47.     rb.ChangeDutyCycle(dutyCycle)
  48.  
  49.  
  50. def leftF(dutyCycle):
  51.     lf.ChangeDutyCycle(dutyCycle)
  52.  
  53.  
  54. def rightF(dutyCycle):
  55.     rf.ChangeDutyCycle(dutyCycle)
  56.  
  57.  
  58. def leftB(dutyCycle):
  59.     lb.ChangeDutyCycle(dutyCycle)
  60.  
  61.  
  62. def rightB(dutyCycle):
  63.     rb.ChangeDutyCycle(dutyCycle)
  64.  
  65.  
  66. def halt():
  67.     lf.ChangeDutyCycle(0)
  68.     rf.ChangeDutyCycle(0)
  69.     lb.ChangeDutyCycle(0)
  70.     rb.ChangeDutyCycle(0)
  71.     init()
  72.  
  73.  
  74. init()
View raw paste Reply