Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.bcm)
- motorL = [2,3,4,17]
- motorR = [27,22,10,9]
- def setupMotor(motor):
- for pin in motor:
- GPIO.setup(pin, GPIO.OUT)
- GPIO.output(pin, 0)
- setupMotor(motorL)
- setupMotor(motorR)
- ccw = [[1,0,0,0],
- [0,1,0,0],
- [0,0,1,0],
- [0,0,0,1]]
- cw = [[0,0,0,1],
- [0,0,1,0],
- [0,1,0,0],
- [1,0,0,0]]
- def resetMotor(motor):
- for pin in range(len(motor)):
- GPIO.output(motor[pin], 0)
- def resetMotors():
- resetMotor(motorL)
- resetMotor(motorR)
- def turn(direction = ""):
- if direction == "left":
- for i in range(256):
- move(cw, cw)
- elif direction == "right":
- for i in range(256):
- move(ccw, ccw)
- else:
- for i in range(512):
- move(ccw, ccw)
- vastAfstand = 41
- def vastForward(vastAfstand):
- for i in range(vastAfstand):
- move (ccw, cw)
- def forward(steps):
- for i in range (steps):
- move (ccw, cw)
- lichtSensor = [14,15,18]
- for pin in lichtSensor:
- GPIO.setup(pin, GPIO.IN)
- #main loop
- try:
- while True (l = 1, m = 1, r = 1):
- vastForward(1)
- turn (1)
- else
- forward(1)
- exception KeyboardInterrupt:
- print ("exception")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement