-
Notifications
You must be signed in to change notification settings - Fork 0
/
servotest.py
28 lines (21 loc) · 1.02 KB
/
servotest.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
import RPi.GPIO as GPIO # Importing RPi library to use the GPIO pins
from time import sleep # Importing sleep from time library to add delay in code
#servo_pin = 21 # Initializing the GPIO 21 for servo motor
#GPIO.setmode(GPIO.BCM) # We are using the BCM pin numbering
#GPIO.setup(servo_pin, GPIO.OUT) # Declaring GPIO 21 as output pin
#p = GPIO.PWM(servo_pin, 50) # Created PWM channel at 50Hz frequency
p.start(2.5)
try:
#while 1: # Loop will run forever
p.ChangeDutyCycle(12.5) # Move servo to 0 degrees
sleep(1) # Delay of 1 sec
#p.ChangeDutyCycle(7.5) # Move servo to 90 degrees
#sleep(1)
p.ChangeDutyCycle(2.5) # Move servo to 180 degrees
sleep(5)
p.ChangeDutyCycle(12.5) # Move servo to 0 degrees
sleep(1) # Delay of 1 sec
# If Keyborad Interrupt (CTRL+C) is pressed
except KeyboardInterrupt:
pass # Go to next line
#GPIO.cleanup() # Make all GPIO pins LOW