Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- from time import sleep
- servoPin = 17
- GPIO.setmode(GPIO.BCM) #use Broadcom numbering scheme
- GPIO.setup(servoPin, GPIO.OUT) #set servoPin as an output
- p = GPIO.PWM(servoPin, 50) #create PWM object called p with freq of 50 Hz
- p.start(2.0) #start PWM with duty cycle of 50%
- def servoTest(speed): #define a function called servoTest that takes in one arg called speed
- p.ChangeDutyCycle(2.0) #make the duty cycle 2: move servo counterclockwise
- sleep(speed) #wait
- p.ChangeDutyCycle(12.0) #make the duty cycle 12: move servo clockwise
- sleep(speed) #wait
- print("Done") ## When loop is complete, print "Done"
- GPIO.cleanup() #stop GPIO
- servoTest(2.0) #run the servoTest function using a speed of 2.0 seconds between movements
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement