I am currently creating a design project that involves controlling several servo motors for a raspberry pi 3. I want to use a keyboard to control the direction of the motors, and I am using curses to take in the keyboard input. My program runs, and the print function shows the correct key that was pressed, but the servos won't spin. I am using the pigpio library to drive the servos. The code I have is below. Any idea what i am doing wrong? Disclaimer: I am not a seasoned programmer, this is my first project with a raspberry pi and python.
import pigpio
import curses
pi=pigpio.pi()
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)
if __name__ == '__main__':
while True:
Char = screen.getch()
if Char== ord('q'):
pi.set_servo_pulsewidth(16, 1600)
print ("rotate left")
if Char==ord('e'):
pi.set_servo_pulsewidth(16,1600)
print (" rotate right")
if Char==ord('a'):
pi.set_servo_pulsewidth(12, 1600)
pi.set_servo_pulsewidth(13, 0)
print ("turn left")
if Char==ord('d'):
pi.set_servo_pulsewidth(12, 0)
pi.set_servo_pulsewidth(13, 1400)
print ("turn right")
if Char==ord('s'):
pi.set_servo_pulsewidth(12, 1400)
pi.set_servo_pulsewidth(13, 1600)
print ("backwards")
if Char==ord('w'):
pi.set_servo_pulsewidth(12, 1400)
pi.set_servo_pulsewidth(13, 1400)
print ("forwards")
if Char == curses.KEY_UP:
pi.set_servo_pulsewidth(18, 1600)
print ("telescope up")
if Char==curses.KEY_DOWN
pi.set_servo_pulsewidth(18, 1400)
print ("telescope Down")
if Char==ord('x'):
print("Program Ended")
break
curses.nocbreak(); screen.keypad(0); curses.echo()
curses.endwin()enter code here