Home        Store        Learn        Blog

Controlling Servo with PCA9685 and Raspberry Pi

Hi, I am trying to control 2 servos from my pca9685 which is connected to my raspberry pi. I have written code that works with key inputs like I want, but I am only able to use one key input, and then I don’t get a response after the first key input. Any idea on how to fix the issue?

import time
import adafruit_servokit import ServoKit

kit = ServoKit(channels=8)
key = input()
angle = 0

while angle <= 100:
	if key == "a":
		kit.servo[0].angle = 100
		time.sleep(1)
	elif key = "aa":
		kit.servo[0].angle = 0
		time.sleep(1)

key= input() was outside of the while loop. It was only being called once.

import time
import adafruit_servokit import ServoKit

kit = ServoKit(channels=8)
angle = 0

while angle <= 100:
key = input()
if key == "a":
	kit.servo[0].angle = 100
	time.sleep(1)
elif key = "aa":
	kit.servo[0].angle = 0
	time.sleep(1)