TRIG = "D13" ECHO = "D12" ultrasonic_sensor = ultrasonic.HCSR04(TRIG, ECHO) while True: dist = ultrasonic_sensor.distance_mm() if dist >= 60: print('if') #motor_left.ctrl_alloc(1, 70) #motor_right.ctrl_alloc(1, 70) motor_left.set_forwards() motor_right.set_forwards() motor_left.duty(90) motor_right.duty(90) sleep(0.1) motor_left.duty(20) motor_right.duty(20) elif dist <= 60: print('elif') #motor_left.ctrl_alloc(0, 70) #motor_right.ctrl_alloc(0, 70) motor_left.set_backwards() motor_right.set_backwards() motor_left.duty(90)
i2c = SoftI2C(scl=Pin("PB13"), sda=Pin("PB14")) apds9960=APDS9960LITE(i2c) speed = 70 while True: IR_readingL = IR_sensorL.value() IR_readingML = IR_sensorML.value() IR_readingMR = IR_sensorMR.value() IR_readingR = IR_sensorR.value() dist = ultrasonic_sensor.distance_mm() motorL.set_forwards() motorR.set_forwards() motorR.duty(speed) motorL.duty(speed) #print(IR_readingL, IR_readingML, IR_readingMR, IR_readingR) if IR_readingML == 1 and IR_readingMR == 1 and IR_readingL == 0 and IR_readingR == 0: motorR.duty(speed) motorL.duty(speed) elif IR_readingML == 1 and IR_readingMR == 1 and IR_readingL == 1 and IR_readingR == 0: motorR.duty(speed*1.25) t.sleep(1) elif IR_readingML == 1 and IR_readingMR == 1 and IR_readingL == 0 and IR_readingR == 1: motorL.duty(speed*1.25) t.sleep(1) #pwm/encoder # pwm = 65