We calculate a weighted average: Position = (E1*w1 + E2*w2 + E3*w3 + E4*w4) / (E1+E2+E3+E4)
# Read sensors sensors = self.read_line_sensors() position = self.calculate_line_position(sensors) mbot2 line follower code
Pro Tip: Print the sensor values to the CyberPi screen to find the exact midpoint between your black and white surfaces. We calculate a weighted average: Position = (E1*w1