Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. from time import sleep
  3.  
  4. GPIO.setwarnings(False)
  5. GPIO.setmode(GPIO.BOARD)
  6.  
  7. GPIOpin=11
  8.  
  9. def setup():
  10. GPIO.setup(GPIOpin,GPIO.OUT)
  11. p = GPIO.PWM(GPIOpin, 50)
  12. p.start(0)
  13.  
  14. def loop():
  15. p.ChangeDutyCycle(3)
  16. sleep(1)
  17. p.ChangeDutyCycle(12)
  18. sleep(1)
  19. SetAngle(30)
  20. sleep(1)
  21.  
  22. def destroy():
  23. p.stop()
  24. GPIO.cleanup()
  25.  
  26. def SetAngle(angle):
  27. duty = angle / 18 + 2
  28. GPIO.output(GPIOpin, True)
  29. p.ChangeDutyCycle(duty)
  30. sleep(1)
  31. GPIO.output(GPIOpin, False)
  32. p.ChangeDutyCycle(0)
  33.  
  34.  
  35. if __name__ == '__main__':
  36. try:
  37. loop()
  38. except KeyboardInterrupt:
  39. destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement