-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrapdoor.py
35 lines (29 loc) · 979 Bytes
/
trapdoor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from adafruit_motorkit import MotorKit
import time
from board import SCL, SDA
import busio
# Import the PCA9685 module. Available in the bundle and here:
# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo
class TrapDoor:
def __init__(self):
self.kit = MotorKit()
i2c = busio.I2C(SCL, SDA)
self.pca = PCA9685(i2c, address=96)
self.pca.frequency = 50 #most servos default to 50hz pulse width
self.door = servo.Servo(self.pca.channels[0])
self.home = 60
self.top = 90
self.bottom = 0
self.spring_and_reset()
def spring_and_reset(self):
self.kit.motor1.throttle = 1
time.sleep(.25)
self.door.angle = self.bottom
time.sleep(1)
self.door.angle = self.top
time.sleep(1)
self.kit.motor1.throttle = None
time.sleep(.25)
self.door.angle = self.home