云台驱动程序
2019-11-06 本文已影响0人
Janeshurmin
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
servo1 = GPIO.PWM(18, 50)
servo1.start(0)
servo2 = GPIO.PWM(23, 50)
servo2.start(0)
try:
while True:
for dc in range(-5,60,5):
i = 7.5+dc*10/180
servo1.ChangeDutyCycle(i)
servo2.ChangeDutyCycle(i)
print(i)
time.sleep(0.5)
for dc in range(55,-10,-5):
i = 7.5+dc*10/180
servo1.ChangeDutyCycle(i)
servo2.ChangeDutyCycle(i)
print(i)
time.sleep(0.5)
except KeyboardInterrupt:
pass
servo1.stop()
servo2.stop()
GPIO.cleanup()