跳至主要内容

树莓派调用舵机云台

# Software PWM Servo.py

import RPi.GPIO as GPIO
import time

P_SERVO = [11,12]
fPWM = 50
a = 10
b = 2

def setup():
global pwm
global pwm1
GPIO.setmode(GPIO.BOARD)
GPIO.setup(P_SERVO, GPIO.OUT)
pwm = GPIO.PWM(P_SERVO[0], fPWM)
pwm1 = GPIO.PWM(P_SERVO[1], fPWM)
pwm.start(0)
pwm1.start(0)

def setDirection(direction):
duty = a / 180 * direction + b
pwm.ChangeDutyCycle(2)
pwm1.ChangeDutyCycle(2)
time.sleep(1)
pwm.ChangeDutyCycle(12)
pwm1.ChangeDutyCycle(12)
time.sleep(1)
print "direction =", direction, "-> duty =", duty
time.sleep(1)
print "starting"
setup()
for direction in range(0, 10, 10):
setDirection(direction)
direction = 0
setDirection(0)
GPIO.cleanup()
print "done"

评论

此博客中的热门博文

css 屏幕横向滚动

  <div  class ="tech-slideshow" > <div class ="mover-1" ></div> <div class ="mover-2" ></div> </div> .tech-slideshow { height: 200px; max-width: 800px; margin: 0 auto; position: relative; overflow: hidden; transform: translate3d(0, 0, 0); } .tech-slideshow > div { height: 200px; width: 2526px; background: url(http://cdn.oushidai.com/static/upload/2018/11/12/20181112154712000000_1_84215_69.jpg); position: absolute; top: 0; left: 0; height: 100%; transform: translate3d(0, 0, 0); } .tech-slideshow .mover-1 { animation: moveSlideshow 60s linear infinite; } .tech-slideshow .mover-2 { opacity: 0; transition: opacity 0.5s ease-out; background-position: 0 -200px; animation: moveSlideshow 20s linear infinite; } .tech-slideshow:hover .mover-2 { opacity: 1; } @keyframes moveSlideshow { 100% { transform: translateX(-66.6666%); } }