Tutorial

Table Of Contents
86
# Initialize servo angle
pwm = Adafruit_PCA9685.PCA9685()
pwm.set_pwm_freq(50)
pwm0_direction = 1
pwm0_init = num_import_int('init_pwm0 = ')
pwm0_max = 520
pwm0_min = 100
pwm0_pos = pwm0_init
pwm1_direction = 1
pwm1_init = num_import_int('init_pwm1 = ')
pwm1_max = 520
pwm1_min = 100
pwm1_pos = pwm1_init
pwm2_direction = 1
pwm2_init = num_import_int('init_pwm2 = ')
pwm2_max = 520
pwm2_min = 100
pwm2_pos = pwm2_init
while True:
# The pan-tit servo rotates to the left, middle and right directions and uses ultrasonic to scan and record the distance
of obstacles
if scanPos == 1:
pwm.set_pwm(scanServo, 0, pwm1_init + scanRange)
time.sleep(0.3)
scanList[0] = ultra.checkdist()
elif scanPos == 2:
pwm.set_pwm(scanServo, 0, pwm1_init)
time.sleep(0.3)
scanList[1] = ultra.checkdist()
elif scanPos == 3:
pwm.set_pwm(scanServo, 0, pwm1_init - scanRange)
time.sleep(0.3)
scanList[2] = ultra.checkdist()
scanPos += scanDir
# If the scanning angle is not within the set range
if scanPos > scanNum or scanPos < 1: