class GongBerry: def __init__(self, numRatches): if numRatches < 1 or numRatches > 20: raise ValueError('Needs to be between 1 and 20') self.numRatches = numRatches self.ss = ServoSix() self.period = 0.7 def open(self): self.ss.set_servo(2, 170) time.sleep(self.period) self.ss.set_servo(1, 0) def close(self): self.ss.set_servo(2, 150) self.ss.set_servo(1, 90) def rat(self): self.ss.set_servo(2, 150) time.sleep(self.period) self.ss.set_servo(2, 50) time.sleep(self.period) def doit(self): try: self.close() for x in range(self.numRatches): self.rat() self.open() finally: self.ss.cleanup() time.sleep(1)
import time from servosix import ServoSix ss = ServoSix() recording = [[155, 85, 80, 30], [155, 90, 80, 40], [155, 95, 80, 55], [155, 100, 80, 65], [155, 105, 80, 75], [155, 100, 80, 65], [155, 95, 80, 50], [155, 90, 80, 40], [155, 85, 80, 30], [145, 85, 75, 30], [135, 85, 70, 30], [120, 85, 65, 30], [110, 85, 60, 30], [100, 85, 55, 30], [110, 85, 60, 30], [125, 85, 65, 30], [135, 85, 70, 30], [145, 85, 75, 30], [155, 85, 80, 30]] def playback(): print(recording) for x in range(0, len(recording)-1): ss.set_servo(1, recording[x][0]) ss.set_servo(2, recording[x][1]) ss.set_servo(3, recording[x][2]) ss.set_servo(4, recording[x][3]) time.sleep(0.05) try: while True: playback() except: ss.cleanup()
[90, 85, 85, 10], [85, 85, 85, 10], [80, 85, 85, 10], [75, 85, 85, 10], [70, 85, 85, 10], [70, 85, 85, 10], [75, 85, 85, 10], [80, 85, 85, 10], [85, 85, 85, 10], [90, 85, 85, 10], [85, 85, 85, 10], [80, 85, 85, 10], [75, 85, 85, 10], [70, 85, 85, 10], [75, 85, 85, 10], [80, 85, 85, 10], [85, 85, 85, 10], [90, 85, 85, 10], [95, 85, 85, 10], [100, 85, 85, 10], [105, 85, 85, 10], [110, 85, 85, 10], [115, 85, 85, 10], [120, 85, 85, 10], [125, 85, 85, 10]] def playback(): print(recording) for x in range(0, len(recording) - 1): ss.set_servo(1, recording[x][0]) ss.set_servo(2, recording[x][1]) ss.set_servo(3, recording[x][2]) ss.set_servo(4, recording[x][3]) time.sleep(0.05) try: while True: if GPIO.input(PIR_PIN): print("Triggered") playback() time.sleep(1) except: ss.cleanup()