Created
May 15, 2021 10:47
-
-
Save chilin0525/3bf675a2bff07ba50e8769255157bc80 to your computer and use it in GitHub Desktop.
sg90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
servoPIN = 2 | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(servoPIN, GPIO.OUT) | |
pwm = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz | |
pwm.start(0) # Initialization | |
try: | |
pwm.ChangeDutyCycle(5) # left -90 deg position | |
time.sleep(1) | |
pwm.ChangeDutyCycle(7.5) # neutral position | |
time.sleep(1) | |
pwm.ChangeDutyCycle(10) # right +90 deg position | |
time.sleep(1) | |
except KeyboardInterrupt: | |
p.stop() | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment