Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setup(25, GPIO.OUT)
  6.  
  7. p = GPIO.PWM(25, 50)
  8.  
  9. print("center")
  10. p.start(7.5)
  11. time.sleep(2)
  12. print("45 degree")
  13. p.ChangeDutyCycle(5)
  14. time.sleep(2)
  15. print("The other 45 degree")
  16. p.ChangeDutyCycle(10)
  17. time.sleep(2)
  18. print("Center again")
  19. p.ChangeDutyCycle(7.5)
  20. time.sleep(2)
  21. print("stop")
  22. p.stop()
  23. GPIO.cleanup()
  24.  
  25. from gpiozero import Servo
  26. from time import sleep
  27.  
  28. myGPIO=25
  29.  
  30. myCorrection=0.45
  31. maxPW=(2.0+myCorrection)/1000
  32. minPW=(1.0-myCorrection)/1000
  33.  
  34. servo = Servo(myGPIO,min_pulse_width=minPW,max_pulse_width=maxPW)
  35.  
  36. while True:
  37. servo.value=0
  38. print("0")
  39. sleep(10)
  40. servo.value=0.6
  41. print("0")
  42. sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement