Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Adafruit_BBIO.PWM as PWM
- import Adafruit_BBIO.GPIO as GPIO
- import Adafruit_BBIO.ADC as ADC
- import time
- ADC.setup()
- servoPin="P8_13"
- echo = "P9_12"
- trig = "P9_15"
- led = "P9_41"
- GPIO.setup(trig,GPIO.OUT)
- GPIO.setup(echo,GPIO.IN)
- GPIO.setup(led,GPIO.OUT)
- analogPin="P9_40"
- PWM.start(servoPin,2.6,60)
- def ultra_sonic():
- pulse_start = 0
- pulse_end = 0
- GPIO.output(trig, GPIO.LOW)
- GPIO.output(trig, GPIO.HIGH)
- time.sleep(0.00001)
- GPIO.output(trig, GPIO.LOW)
- while GPIO.input(echo)==0:
- pulse_start = time.time()
- while GPIO.input(echo)==1:
- pulse_end = time.time()
- pulse_duration = pulse_end - pulse_start
- distance = pulse_duration * 17150
- distance = round(distance, 2)
- if distance <= 10:
- print "close"
- else:
- pass
- def move(duty):
- PWM.set_duty_cycle(servoPin,duty)
- time.sleep(0.01)
- ultra_sonic()
- while 1:
- potVal=ADC.read(analogPin)
- duty = potVal * 5.43
- if (duty < 1):
- duty = 0.60 * 5.43
- move(round(duty, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement