Skip to content

Instantly share code, notes, and snippets.

@akbsteam
Created March 18, 2013 13:23
Show Gist options
  • Save akbsteam/5187102 to your computer and use it in GitHub Desktop.
Save akbsteam/5187102 to your computer and use it in GitHub Desktop.
#!/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