Guest User

Untitled

a guest
Nov 13th, 2016
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from gpiozero import Robot
  2. from gpiozero import DistanceSensor
  3. from gpiozero import LED
  4. from time import sleep
  5.  
  6. leftPins = (21, 16)
  7. rightPins = (12, 1)
  8.  
  9. robot = Robot(left=leftPins, right=rightPins)
  10.  
  11. sensorLeft = DistanceSensor(echo=14, trigger=15, queue_len=10)
  12. sensorRight = DistanceSensor(echo=24, trigger=23, queue_len=10)
  13.  
  14. led = LED(pin=18)
  15.  
  16. led.blink(1, 1, 2, background=False)
  17.  
  18. while True:
  19. if sensorLeft.distance < 0.4:
  20. #led.value = True
  21. robot.backward()
  22. sleep(0.5)
  23. robot.right()
  24. sleep(0.5)
  25. if sensorRight.distance < 0.4:
  26. led.value = True
  27. robot.backward()
  28. sleep(0.5)
  29. robot.left()
  30. sleep(0.5)
  31. robot.forward(0.5)
  32. led.value = False
  33. sleep(0.1)
RAW Paste Data