Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # import sys
- from Servo import *
- from time import sleep
- # create instance of ServoCtrl on i2c bus 2 at address 64 using 60hz pwm frequency.
- # change 64 to 0x7f for servo cape
- servos = ServoCtrl(2, 0x7f, 50)
- # add a servo to controller, using channel 15. servo max rotation is 180 degrees.
- servos.addServos([Servo(name = 'servo1', channel = 0, max_angle = 180),
- Servo(name = 'servo2', channel = 1, max_angle = 180),
- Servo(name = 'servo3', channel = 2, max_angle = 180),
- Servo(name = 'servo4', channel = 3, max_angle = 180),
- Servo(name = 'servo5', channel = 4, max_angle = 180),
- Servo(name = 'servo6', channel = 5, max_angle = 180)
- ])
- # add some servos using JSON notation
- servos.addServosJSON([{'name':'servo9', 'channel':8, 'max_angle':180},
- {'name':'servo10', 'channel':9, 'max_angle':180},
- {'name':'servo11', 'channel':10, 'max_angle':180},
- {'name':'servo12', 'channel':11, 'max_angle':180},
- {'name':'servo13', 'channel':12, 'max_angle':180},
- {'name':'servo14', 'channel':13, 'max_angle':180}
- ])
- servos.enablePWMs(True)
- print(servos.servos)
- for i in range(0, 30, 2):
- # move servo15 to 0 degrees and servo2 to 90 degrees.
- servos.moveServos([ServoPos(name = "servo1", angle = 0),
- ServoPos(name = "servo2", angle = 0),
- ServoPos(name = "servo3", angle = 0),
- ServoPos(name = "servo4", angle = 0),
- ServoPos(name = "servo5", angle = 0),
- ServoPos(name = "servo6", angle = 0)
- ])
- sleep(0.25)
- # move both servos to 50%
- servos.moveServosJSON([{'name':"servo9", 'percent':50},
- {'name':"servo10", 'percent':50},
- {'name':"servo11", 'percent':50},
- {'name':"servo12", 'percent':50},
- {'name':"servo13", 'percent':50},
- {'name':"servo14", 'percent':50}
- ])
- sleep(0.25)
- #move servo15 to max rotation and servo2 to 0
- # create a list and then append moves to it.
- #servolist = []
- #servolist.append(ServoPos(name = "servo1", angle = servos.get_servo_max_angle("servo1")))
- #servolist.append(ServoPos(name = "servo2", angle = 0) )
- #servos.moveServos(servolist)
- #sleep(1)
- # use JSON to move servos
- #for l in range(0, 2):
- servos.moveServosJSON([{'name':"servo9", 'angle':80},
- {'name':"servo10", 'angle':80},
- {'name':"servo11", 'angle':80},
- {'name':"servo12", 'angle':80},
- {'name':"servo13", 'angle':80},
- {'name':"servo14", 'angle':80}
- ])
- sleep(0.25)
- # move both servos to 90%
- servos.moveServos([ServoPos(name = "servo1", percent = 90),
- ServoPos(name = "servo2", percent = 90),
- ServoPos(name = "servo3", percent = 90),
- ServoPos(name = "servo4", percent = 90),
- ServoPos(name = "servo5", percent = 90),
- ServoPos(name = "servo6", percent = 90)
- ])
- sleep(0.25)
- # move servo15 to max rotation and servo2 to 0
- # servos.moveServosJSON([{'name':"servo1", 'angle':servos.get_servo_max_angle("servo1")},
- # {'name':"servo2", 'angle':0}
- # ])
- # sleep(1)
- servos.enablePWMs(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement