-
Notifications
You must be signed in to change notification settings - Fork 2
/
servo.py
60 lines (46 loc) · 1.28 KB
/
servo.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 RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
servoUltraSonicPin = 17
servoCameraUpDownPin = 20
servoCameraLeftRightPin = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoUltraSonicPin, GPIO.OUT)
GPIO.setup(servoCameraUpDownPin, GPIO.OUT)
GPIO.setup(servoCameraLeftRightPin, GPIO.OUT)
servoUltraSonic = GPIO.PWM(servoUltraSonicPin, 50)
servoCameraUpDown = GPIO.PWM(servoCameraUpDownPin, 50)
servoCameraLeftRight = GPIO.PWM(servoCameraLeftRightPin, 50)
servoUltraSonic.start(7)
servoCameraUpDown.start(6.5)
servoCameraLeftRight.start(7.5)
time.sleep(0.1)
def ultraSonicLeft():
servoUltraSonic.ChangeDutyCycle(13)
def ultraSonicRight():
servoUltraSonic.ChangeDutyCycle(3)
def ultraSonicPosition():
servoUltraSonic.ChangeDutyCycle(8)
def cameraUp():
servoCameraUpDown.ChangeDutyCycle(9)
def cameraDown():
servoCameraUpDown.ChangeDutyCycle(5)
def cameraLeft():
servoCameraLeftRight.ChangeDutyCycle(13)
def cameraRight():
servoCameraLeftRight.ChangeDutyCycle(3)
def cameraPosition():
servoCameraLeftRight.ChangeDutyCycle(7.5)
servoCameraUpDown.ChangeDutyCycle(6.5)
def cameraUpDown(x):
if x>13:
x = 13
if x<0:
x = 0
servoCameraUpDown.ChangeDutyCycle(x)
def cameraLeftRight(x):
if x>13:
x = 13
if x<0:
x = 0
servoCameraLeftRight.ChangeDutyCycle(x)