if (centre_x <= -20 or centre_x >= 20): if (centre_x < 0): flag = 0 rightturn() time.sleep(0.025) elif (centre_x > 0): flag = 1 leftturn() time.sleep(0.025) forward() time.sleep(0.00003125) stop() time.sleep(0.00625) else: stop() time.sleep(0.01) else: #if it founds the ball and it is too close it lights up the led. GPIO.output(LED_PIN, GPIO.HIGH) time.sleep(0.1) stop() time.sleep(0.1) #cv2.imshow("draw",frame) rawCapture.truncate( 0) # clear the stream in preparation for the next frame if (cv2.waitKey(1) & 0xff == ord('q')): break GPIO.cleanup() #free all the GPIO pins