-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo.py
56 lines (40 loc) · 1.54 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
# This is a list of callable functions for the servo going directly into the pi (signal pin being in GPIO 17 - Board number 11)
#Board pinouts servo -> Pi
#V+(Orange) -> 5V (On Pi)
#GND(Brown) -> GND (On Pi)
#PWM(Yellow) -> GPIO 17/Pin 11
import time
#imports
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT) # sets GPIO pin 11 as an output
pwm=GPIO.PWM(11, 50)
pwm.start(0)
def setAngle(angle): #goes to set angle (0-170)
duty = angle / 18 + 3
GPIO.output(11, True)
pwm.ChangeDutyCycle(duty)
time.sleep(1)
GPIO.output(11, False)
pwm.ChangeDutyCycle(duty)
def left(): # go to the left
setAngle(170)
def centre(): #go to neutral
setAngle(90)
def right(): #got the right
setAngle(0)
def exit(): #exit() will make usre there is a GPIO.cleanup() command
pwm.stop()
GPIO.cleanup()
def press(angle): # Press to set angle then go to neutral position
setAngle(angle)
time.sleep(0.01)
setAngle(85)
def leftpress(): #where the servo is mounted on the left of the short push button (with the cables going upwards)
press(70)
def rightpress(): #where the servo is mounted on the right of the short push button (with the cables going upwards)
press(110)
def leftswitch(): #where the servo is mounted on the left of the switch (with the cables going upwards)
press(70) # need to test what the perfect angle is NOT 70
def rightswitch(): #where the servo is mounted on the right of the switch (with the cables going upwards)
press(110) # need to test what the perfect angle is NOT 110