Created
March 18, 2013 13:23
-
-
Save akbsteam/5187102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from Adafruit_PWM_Servo_Driver import PWM | |
import time | |
class ServoControl(object): | |
current = 200 | |
direction = 1 | |
def __init__(self, pwm, pin, sMax, sMin): | |
self.pwm = pwm | |
self.pin = pin | |
self.sMax = sMax | |
self.sMin = sMin | |
def scan(self): | |
self.current += self.direction | |
if (self.current > self.sMax): | |
self.direction = -1 | |
elif (self.current < self.sMin): | |
self.direction = 1 | |
def move(self): | |
self.scan() | |
self.pwm.setPWM(self.pin, 0, self.current) | |
pwm = PWM(0x40) | |
pwm.setPWMFreq(50) | |
twistServo = ServoControl(pwm, 0, 300, 200) | |
nodServo = ServoControl(pwm, 15, 500, 120) | |
while (True): | |
twistServo.move() | |
nodServo.move() | |
time.sleep(0.005) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment