Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. from time import sleep
  3.  
  4. servoPin = 17
  5.  
  6. GPIO.setmode(GPIO.BCM) #use Broadcom numbering scheme
  7. GPIO.setup(servoPin, GPIO.OUT) #set servoPin as an output
  8.  
  9.  
  10. p = GPIO.PWM(servoPin, 50) #create PWM object called p with freq of 50 Hz
  11. p.start(2.0) #start PWM with duty cycle of 50%
  12.  
  13. def servoTest(speed): #define a function called servoTest that takes in one arg called speed
  14.     p.ChangeDutyCycle(2.0) #make the duty cycle 2: move servo counterclockwise
  15.     sleep(speed) #wait
  16.     p.ChangeDutyCycle(12.0) #make the duty cycle 12: move servo clockwise
  17.     sleep(speed) #wait
  18.     print("Done") ## When loop is complete, print "Done"
  19.     GPIO.cleanup() #stop GPIO
  20.  
  21.  
  22. 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