-
-
Save neosarchizo/4ace4b5ec9ee814afc3b to your computer and use it in GitHub Desktop.
[Raspberry Pi] 바보상자
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 | |
button = 4 | |
servo = 18 | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
GPIO.setup(servo, GPIO.OUT) | |
pwm = GPIO.PWM(servo, 50) | |
pwm.start(4) | |
try: | |
while True: | |
if GPIO.input(button): | |
pwm.ChangeDutyCycle(12) | |
while GPIO.input(button): pass | |
pwm.ChangeDutyCycle(4) | |
finally: | |
pwm.stop() | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment