Skip to content

Instantly share code, notes, and snippets.

@ducky-hong
Created November 10, 2018 21:21
Show Gist options
  • Save ducky-hong/c67a86fc5b83962d62d89dc4aebffcd7 to your computer and use it in GitHub Desktop.
Save ducky-hong/c67a86fc5b83962d62d89dc4aebffcd7 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50)
p.start(7.5)
try:
while True:
p.ChangeDutyCycle(7.5) # turn towards 90 degree
time.sleep(1) # sleep 1 second
p.ChangeDutyCycle(2.5) # turn towards 0 degree
time.sleep(1) # sleep 1 second
p.ChangeDutyCycle(12.5) # turn towards 180 degree
time.sleep(1) # sleep 1 second
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment