Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. # Servo Control
  2. import time
  3. import wiringpi
  4.  
  5. # use 'GPIO naming'
  6. wiringpi.wiringPiSetupGpio()
  7.  
  8. # set #18 to be a PWM output
  9. wiringpi.pinMode(17, wiringpi.GPIO.PWM_OUTPUT)
  10.  
  11. # set the PWM mode to milliseconds stype
  12. wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
  13.  
  14. # divide down clock
  15. wiringpi.pwmSetClock(192)
  16. wiringpi.pwmSetRange(2000)
  17.  
  18. delay_period = 0.01
  19.  
  20. while True:
  21. for pulse in range(50, 250, 1):
  22. wiringpi.pwmWrite(17, pulse)
  23. time.sleep(delay_period)
  24. for pulse in range(250, 50, -1):
  25. wiringpi.pwmWrite(17, pulse)
  26. time.sleep(delay_period)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement