Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gpiozero import DistanceSensor
- from gpiozero import Servo
- from time import sleep
- import random
- sensor = DistanceSensor(echo=5, trigger=19)
- def scanLeft():
- myGPIO = 6
- scanLeft = Servo(myGPIO)
- for x in range(8):
- randomLeft = random.uniform(-0.3, 0.3)
- sleep(0.005)
- scanLeft.value = randomLeft
- print(scanLeft.value)
- def scanRight():
- myGPIO = 13
- scanRight = Servo(myGPIO)
- for x in range(8):
- randomRight = random.uniform(-0.3, 0.3)
- sleep(0.005)
- scanRight.value = randomRight
- print(scanRight.value)
- def leftForward():
- myGPIO=6
- myCar=Servo(myGPIO)
- for x in range(10):
- sleep(0.005)
- myCar.value = 1
- def rightForward():
- myGPIO=13
- myCar=Servo(myGPIO)
- for x in range(10):
- sleep(0.005)
- myCar.value = 1
- def backward():
- myGPIO=6
- myGPIO1=13
- myCar=Servo(myGPIO)
- myCar1=Servo(myGPIO1)
- for x in range(4):
- sleep(0.5)
- myCar.value=-0.4
- myCar1.value=-0.4
- while True:
- sleep(0.01)
- distance = sensor.distance * 100
- if distance <= 20 and distance > 6:
- leftForward()
- distance = sensor.distance * 100
- rightForward()
- elif distance <= 5:
- backward()
- elif distance > 20:
- scanLeft()
- distance = sensor.distance * 100
- scanRight()
- distance = sensor.distance * 100
- print(distance)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement