servoMax = 600  # Max pulse length out of 4096


def setServoPulse(channel, pulse):
    pulseLength = 1000000  # 1,000,000 us per second
    pulseLength /= 60  # 60 Hz
    print "%d us per period" % pulseLength
    pulseLength /= 4096  # 12 bits of resolution
    print "%d us per bit" % pulseLength
    pulse *= 1000
    pulse /= pulseLength
    pwm.setPWM(channel, 0, pulse)


pwm.setPWMFreq(60)  # Set frequency to 60 Hz

while (True):
    pwm.setPWM(3, 0, 375)
    time.sleep(1)
    pwm.setPWM(3, 0, 450)
    time.sleep(1)
    pwm.setPWM(3, 0, 525)
    time.sleep(1)
    pwm.setPWM(3, 0, 450)
    time.sleep(1)
'''	pwm.setPWM(0, 0, servoMin)
	time.sleep(1)
	pwm.setPWM(0, 0, servoMax)
	time.sleep(1)
'''
servoMax = 600  # Max pulse length out of 4096

def setServoPulse(channel, pulse):
	pulseLength = 1000000                   # 1,000,000 us per second
	pulseLength /= 60                       # 60 Hz
	print "%d us per period" % pulseLength
	pulseLength /= 4096                     # 12 bits of resolution
	print "%d us per bit" % pulseLength
	pulse *= 1000
	pulse /= pulseLength
	pwm.setPWM(channel, 0, pulse)

pwm.setPWMFreq(60)                        # Set frequency to 60 Hz

while (True):
	pwm.setPWM(3, 0, 375)
	time.sleep(1)
	pwm.setPWM(3, 0, 450)
	time.sleep(1)
	pwm.setPWM(3, 0, 525)
	time.sleep(1)
	pwm.setPWM(3, 0, 450)
	time.sleep(1)


'''	pwm.setPWM(0, 0, servoMin)
	time.sleep(1)
	pwm.setPWM(0, 0, servoMax)
	time.sleep(1)
'''
Exemple #3
0
#!/usr/bin/python
import time
from Sunfounder_PWM_Servo_Driver import PWM

pwm = PWM(0x40, True)
pwm.setPWMFreq(60)


# Min found around 150
# Max found around 700
servoMin = 150
servoMax = 700



print "Hello, servo-world"

while (True):
  # Change speed of continuous servo on channel O
  pwm.setPWM(0, 0, servoMin)
  time.sleep(1)
  pwm.setPWM(0, 0, servoMax)
  time.sleep(1)
  print "Looping!"