from PiMotor import Sensor import time go = "true" while go == "true": us = Sensor("ULTRASONIC", 15) us.trigger() if us.Triggered: print("Bremsen")
from PiMotor import Sensor import time go = "true" while go == "true": us1 = Sensor("IR1", 1) us1.trigger() us2 = Sensor("IR2", 1) us2.trigger() if us1.Triggered and us2.Triggered: print("stop") elif us1.Triggered: print("rechts") elif us2.Triggered: print("links")
ir3 = Sensor("IR3", 10) #To drive all motors together motorAll = PiMotor.LinkedMotors(m1, m2, m3, m4) def trigIR(): ir1.trigger() ir2.trigger() if ir1.Triggered: motorAll.reverse(100) time.sleep(0.7) motorAll.stop() print("Front Line Detected") if ir2.Triggered: motorAll.forward(100) time.sleep(0.7) motorAll.stop() print("Back Line Detected") try: while true: ir3.trigger() if ir3.Triggered: motorAll.forward(100) time.sleep(1) motorAll.stop() except KeyboardInterrupt: GPIO.cleanup()
import sys sys.path.append("/home/pi/MotorShield") from PiMotor import Arrow from PiMotor import Sensor from PiMotor import Motor m1 = Motor("MOTOR1", 1) m2 = Motor("MOTOR2", 1) m3 = Motor("MOTOR3", 1) m4 = Motor("MOTOR4", 1) us = Sensor("ULTRASONIC", 10) ir1 = Sensor("IR1", 0) ir2 = Sensor("IR2", 0) while True: ir1.trigger() if ir1.Triggered: print("No Line Detected - IR1") else: print("Black Line Detected - IR1") ir2.trigger() if ir2.Triggered: print("No Line Detected - IR2") else: print("Black Line Detected - IR2") # except KeyboardInterrupt: # GPIO.cleanup()