def main(): try: servo = Servo() sensor = Sensor(23,24,25) while True: digit = getObject() sensor.turnLED() servo.changeRotation() dist = sensor.distance() time.sleep(0.5) print ("Measured Distance = %.1f cm" % dist) print (digit) time.sleep(1) # Reset by pressing CTRL + C except KeyboardInterrupt: servo.stop() print("Measurement stopped by User") GPIO.cleanup()
pwm_pin_1 = 19 motor1_cw = 4 motor1_ccw = 17 motor_left = Motor(pwm_pin_1, motor1_cw, motor1_ccw) pwm_pin_2 = 19 motor2_cw = 20 motor2_ccw = 26 motor_right = Motor(pwm_pin_2, motor2_cw, motor2_ccw) power = 30 direction = "cw" # dist = 0 dist = sensor1.distance() # motor_right.turn_on(power, direction) # motor_left.turn_on(power, direction) try: while dist > 100: dist = sensor1.distance() if dist > 700: power = 90 elif dist < 500: power = 50 elif dist < 300: power = 30 print("Measured distance: %.1f mm" % dist) motor_right.turn_on(power, direction) # motor_left.turn_on(power, direction) # time.sleep(0.1)