Srxon05

gpio.PWM servo

Nov 22nd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. import time
  2. import RPi.GPIO as GPIO
  3. GPIO.setmode(GPIO.BOARD)
  4. GPIO.setup(12, GPIO.OUT)
  5.  
  6. p = GPIO.PWM(12, 50)  # channel=12 frequency=50Hz
  7. p.start(0)
  8. try:
  9.     while 1:
  10.         for dc in range(0, 101, 5):
  11.             p.ChangeDutyCycle(dc)
  12.             time.sleep(0.1)
  13.         for dc in range(100, -1, -5):
  14.             p.ChangeDutyCycle(dc)
  15.             time.sleep(0.1)
  16. except KeyboardInterrupt:
  17.     pass
  18. p.stop()
  19. GPIO.cleanup()
Add Comment
Please, Sign In to add comment