This commit is contained in:
Steven Tracey 2023-04-02 11:21:22 -04:00
parent d680fc0dfd
commit 9836e6058f

13
main.py
View File

@ -36,10 +36,10 @@ def move_to_light():
is_facing_light = False
while not is_facing_light:
offset = light_sensor_1.read_u16() - light_sensor_2.read_u16()
if offset > 100 and cur_deg > 0:
if offset > 50 and cur_deg > 0:
cur_deg = cur_deg - 1
servo(cur_deg)
elif offset < -100 and cur_deg < 180:
servo(cur_deg - 5)
elif offset < -50 and cur_deg < 180:
cur_deg = cur_deg + 1
servo(cur_deg)
else:
@ -58,20 +58,21 @@ while True:
while reset_button.value() == 1:
time.sleep(.1)
led.high()
continue
diff = light_sensor_1.read_u16() - light_sensor_2.read_u16()
run_avg = shift_array(run_avg, diff)
if calibrate_button.value() == 1:
cal_threshold = int((light_sensor_1.read_u16() + light_sensor_2.read_u16()) / 2) - 50
cal_threshold = int((light_sensor_1.read_u16() + light_sensor_2.read_u16()) / 2) - 25
while calibrate_button.value() == 1:
time.sleep(.1)
if light_sensor_1.read_u16() > cal_threshold and light_sensor_2.read_u16() > cal_threshold:
if cal_threshold == 0 or (light_sensor_1.read_u16() > cal_threshold and light_sensor_2.read_u16() > cal_threshold):
continue
num_over = 0
first_iter = True
sign = True
for i in run_avg:
cur_num = i
if abs(cur_num) > 150:
if abs(cur_num) > 75:
if first_iter:
if cur_num >= 0:
sign = True