forked from EbenKouao/Pi-Smart-Doorbell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservo.py
More file actions
executable file
·34 lines (28 loc) · 738 Bytes
/
servo.py
File metadata and controls
executable file
·34 lines (28 loc) · 738 Bytes
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
#!/usr/bin/python
import sys
import time
import RPi.GPIO as GPIO
def main(argv):
start = argv[1]
end = argv[2]
delay = argv[3]
loop = argv[4]
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(11, GPIO.OUT)
servo1 = GPIO.PWM(11, 50)
servo1.start(0)
for i in range(0, int(loop)):
for dc in range(int(start), int(end), 1):
servo1.ChangeDutyCycle(2+(dc/18))
time.sleep(float(delay))
servo1.ChangeDutyCycle(0)
time.sleep(0.3)
print(dc)
servo1.stop()
GPIO.cleanup()
if __name__ == "__main__":
if len(sys.argv) < 5:
print ("servo.py <start> <end> <delay> <loop>")
else:
main(sys.argv)