-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservoTest5.py
60 lines (47 loc) · 1.17 KB
/
servoTest5.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Import libraries
import RPi.GPIO as GPIO
import time
# Set GPIO numbering mode
GPIO.setmode(GPIO.BOARD)
# Set pins 11 & 12 as outputs, and define as PWM servo1 & servo2
GPIO.setup(11,GPIO.OUT)
servo1 = GPIO.PWM(11,50) # pin 11 for servo1
GPIO.setup(12,GPIO.OUT)
servo2 = GPIO.PWM(12,50) # pin 12 for servo2
# Start PWM running on both servos, value of 0 (pulse off)
servo1.start(0)
servo2.start(0)
# Turn servo1 to 90
servo1.ChangeDutyCycle(7)
time.sleep(0.5)
servo1.ChangeDutyCycle(0)
# Wait for 2 seconds
time.sleep(2)
# Turn servo2 to 90 & servo1 back to 0
servo2.ChangeDutyCycle(7)
servo1.ChangeDutyCycle(2)
time.sleep(0.5)
servo2.ChangeDutyCycle(0)
servo1.ChangeDutyCycle(0)
# Wait again for 2 seconds! :)
time.sleep(2)
# Turn servo2 to 180 & servo1 to 90
servo2.ChangeDutyCycle(12)
servo1.ChangeDutyCycle(7)
time.sleep(0.5)
servo2.ChangeDutyCycle(0)
servo1.ChangeDutyCycle(0)
# Another little 2 second pause...
time.sleep(2)
# Turn both servos back to 0
servo2.ChangeDutyCycle(2)
servo1.ChangeDutyCycle(2)
time.sleep(0.5)
servo2.ChangeDutyCycle(0)
servo1.ChangeDutyCycle(0)
time.sleep(2)
#Clean things up at the end
servo1.stop()
servo2.stop()
GPIO.cleanup()
print ("Goodbye")