Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import Adafruit_BBIO.PWM as PWM
  2. import Adafruit_BBIO.GPIO as GPIO
  3. import Adafruit_BBIO.ADC as ADC
  4. import time
  5.  
  6. ADC.setup()
  7. servoPin="P8_13"
  8. echo = "P9_12"
  9. trig = "P9_15"
  10. led = "P9_41"
  11.  
  12. GPIO.setup(trig,GPIO.OUT)
  13. GPIO.setup(echo,GPIO.IN)
  14.  
  15. GPIO.setup(led,GPIO.OUT)
  16.  
  17. analogPin="P9_40"
  18.  
  19.  
  20. PWM.start(servoPin,2.6,60)
  21.  
  22. def ultra_sonic():
  23. pulse_start = 0
  24. pulse_end = 0
  25.  
  26. GPIO.output(trig, GPIO.LOW)
  27.  
  28. GPIO.output(trig, GPIO.HIGH)
  29. time.sleep(0.00001)
  30. GPIO.output(trig, GPIO.LOW)
  31. while GPIO.input(echo)==0:
  32. pulse_start = time.time()
  33.  
  34. while GPIO.input(echo)==1:
  35. pulse_end = time.time()
  36.  
  37. pulse_duration = pulse_end - pulse_start
  38.  
  39. distance = pulse_duration * 17150
  40.  
  41. distance = round(distance, 2)
  42.  
  43. if distance <= 10:
  44. print "close"
  45. else:
  46. pass
  47.  
  48. def move(duty):
  49. PWM.set_duty_cycle(servoPin,duty)
  50. time.sleep(0.01)
  51. ultra_sonic()
  52.  
  53. while 1:
  54.  
  55. potVal=ADC.read(analogPin)
  56. duty = potVal * 5.43
  57. if (duty < 1):
  58. duty = 0.60 * 5.43
  59. move(round(duty, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement