Skip to content

Instantly share code, notes, and snippets.

@natcl
Created August 31, 2019 19:33
Show Gist options
  • Save natcl/38e3cfc2d523afa7510ec97a3af9e667 to your computer and use it in GitHub Desktop.
Save natcl/38e3cfc2d523afa7510ec97a3af9e667 to your computer and use it in GitHub Desktop.
PWM Servo on Pi
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 100)
p.start(5)
time.sleep(2)
for angle in range (25, 180):
duty = float(angle) / 10 + 2.5
print duty
p.ChangeDutyCycle(duty)
time.sleep(0.15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment