def forever(): global Ref, Left, Mid, Right if getGrayscaleValue() != [0, 0, 0]: backward(50) delay(500) set_dir_servo_angle(30) forward(30) delay(500) set_dir_servo_angle(0) else: forward(20)
def outHandle(): global sta, value, direction, Ref, Left, Mid, Right, lastSta, currentSta if lastSta == 'LEFT': set_dir_servo_angle((-30)) backward(10) elif lastSta == 'RIGHT': set_dir_servo_angle(30) backward(10) while True: currentSta = getDirection() if currentSta != lastSta: break delay(1)
def forever(): forward(50) delay(1000) backward(50) delay(1000) forward(50) set_dir_servo_angle((-30)) delay(1000) forward(50) set_dir_servo_angle(30) delay(1000) set_dir_servo_angle(0) stop() delay(2000)
def forever(): global Ref1, distance, Ref2 distance = Ultrasonic(pin_D0, pin_D1).read() if distance >= Ref1: set_dir_servo_angle(0) forward(50) elif distance >= Ref2: set_dir_servo_angle(40) forward(50) delay(500) else: set_dir_servo_angle((-40)) backward(50) delay(500)
def forever(): global distance distance = Ultrasonic(pin_D0, pin_D1).read() print("%s"%distance) delay(100) forward(50) delay(1000) backward(50) delay(1000) forward(50) set_dir_servo_angle((-30)) delay(1000) forward(50) set_dir_servo_angle(30) delay(1000) set_dir_servo_angle(0) stop() delay(2000)