Skip to content

Instantly share code, notes, and snippets.

@jakorten
Last active October 3, 2022 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakorten/53cc4cb0435af9cec507d41ad196c997 to your computer and use it in GitHub Desktop.
Save jakorten/53cc4cb0435af9cec507d41ad196c997 to your computer and use it in GitHub Desktop.
Python code - Basis Lijnvolger
"""
Python code voor Microbit / DFRobot Maqueen Plus
Johan Korten voor Q-Highschool en Hogeschool van Arnhem en Nijmegen
v1.0 okt 2022
"""
sensorL1 = False
sensorL2 = False
lijnInMidden = False
def geefFalseTerug():
return False
def leesMiddelsteLijnSensoren():
global sensorL1, sensorL2, lijnInMidden
sensorL1 = DFRobotMaqueenPlus.read_patrol(Patrol.L1) == 1
sensorL2 = DFRobotMaqueenPlus.read_patrol(Patrol.R1) == 1
lijnInMidden = sensorL1 and sensorL2
return lijnInMidden
def afwijkingRechts():
global sensorL1, sensorL2, lijnInMidden
sensorL1 = DFRobotMaqueenPlus.read_patrol(Patrol.L1) == 0
sensorL2 = DFRobotMaqueenPlus.read_patrol(Patrol.R1) == 1
lijnInMidden = sensorL1 and sensorL2
return lijnInMidden
def robotStoppen():
DFRobotMaqueenPlus.set_rgb_light(RGBLight.RGBA, Color.RED)
DFRobotMaqueenPlus.motot_stop(Motors.ALL)
def afwijkingLinks():
global sensorL1, sensorL2, lijnInMidden
sensorL1 = DFRobotMaqueenPlus.read_patrol(Patrol.L1) == 1
sensorL2 = DFRobotMaqueenPlus.read_patrol(Patrol.R1) == 0
lijnInMidden = sensorL1 and sensorL2
return lijnInMidden
def robotVooruit():
DFRobotMaqueenPlus.set_rgb_light(RGBLight.RGBA, Color.GREEN)
DFRobotMaqueenPlus.motot_run(Motors.ALL, Dir.CW, 75)
def robotNaarLinks():
DFRobotMaqueenPlus.set_rgb_light(RGBLight.RGBR, Color.RED)
DFRobotMaqueenPlus.set_rgb_light(RGBLight.RGBL, Color.GREEN)
DFRobotMaqueenPlus.motot_run(Motors.M1, Dir.CW, 75)
def robotNaarRechts():
DFRobotMaqueenPlus.set_rgb_light(RGBLight.RGBL, Color.RED)
DFRobotMaqueenPlus.set_rgb_light(RGBLight.RGBR, Color.GREEN)
DFRobotMaqueenPlus.motot_run(Motors.M2, Dir.CW, 75)
def on_forever():
if leesMiddelsteLijnSensoren():
robotVooruit()
elif afwijkingLinks():
robotNaarRechts()
elif afwijkingRechts():
robotNaarLinks()
else:
robotStoppen()
basic.forever(on_forever)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment