Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active November 15, 2016 12:41
Show Gist options
  • Select an option

  • Save bennuttall/76902a324db41e5403c0de212e7d07d7 to your computer and use it in GitHub Desktop.

Select an option

Save bennuttall/76902a324db41e5403c0de212e7d07d7 to your computer and use it in GitHub Desktop.
from gpiozero import LineSensor, Robot
robot = Robot(left=(9, 10), right=(7, 8))
line = LineSensor(25)
speed = 0.6
while True:
robot.forward(speed)
line.wait_for_no_line()
robot.left(speed)
line.wait_for_line()
from gpiozero import LineSensor, Robot
robot = Robot(left=(9, 10), right=(7, 8))
line = LineSensor(25)
robot.source_delay = 0.5
speed = 0.6
def look_for_line():
while True:
yield (1, 0.5) # left motor full speed, right motor half speed
yield (0.5, 1) # left motor half speed, right motor full speed
while True:
robot.forward(speed)
line.wait_for_no_line() # go forward until the line is lost
robot.source = look_for_line() # alternate between slight left and slight right
line.wait_for_line() # until the line is found
robot.source = None # unset the source to stop looking left and right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment