I'm trying an object detection program using Python language, and want to connect it to the Raspberry Pi's GPIO.
for code in decode(frame):
decoded_data = code.data.decode("utf-8")
rect_pts = code.rect
print("\nID:", code.data.decode("utf-8"))
if decoded_data in reg_qr:
infoOut = 'Authorized'
bbColor = (0,255,0)
else:
infoOut = 'Un-Authorized'
bbColor = (0,0,255)
pts = np.array([code.polygon], np.int32)
cv2.polylines(frame, [pts], True, bbColor, 3)
cv2.putText(frame, infoOut, (rect_pts[0], rect_pts[1]), cv2.FONT_HERSHEY_SIMPLEX, 1, bbColor,3)
That is the Python code snippet. It runs fine, according to the algorithm. But when I want to drive the servo with this syntax, I can't
if decoded_data in reg_qr:
angle = 90
servo1.ChangeDutyCycle(2+(angle/18))
servo1.ChangeDutyCycle(0)
time.sleep(2)
if distance <= 5.01:
angle = 90
servo1.ChangeDutyCycle(2+(angle/18))
time.sleep(2)
servo1.ChangeDutyCycle(0)
I think it would be the same as driving the servo with the input from the ultrasonic sensor. Turns out I was wrong. Anyone know the solution?