Difference between revisions of "SG90-Servo"
Jump to navigation
Jump to search
(Created page with "= Python Source Code = <source lang='python'> # Servo control # see https://tutorials-raspberrypi.de/raspberry-pi-servo-motor-steuerung/ import RPi.GPIO as GPIO import time...") |
|||
Line 1: | Line 1: | ||
+ | [[File:20190612_084823.jpg|900px]] | ||
= Python Source Code = | = Python Source Code = | ||
<source lang='python'> | <source lang='python'> |
Revision as of 09:42, 12 June 2019
Python Source Code
# Servo control
# see https://tutorials-raspberrypi.de/raspberry-pi-servo-motor-steuerung/
import RPi.GPIO as GPIO
import time
# set the GPIO pin to be used
servoPIN = 23
# set the mode
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
p = GPIO.PWM(servoPIN, 50) # set pulse width modulation (PWM to 50Hz)
# start the pulswidth with a 2.5 cycle
p.start(2.5) # Initialisierung
try:
while True:
p.ChangeDutyCycle(5)
time.sleep(0.5)
p.ChangeDutyCycle(7.5)
time.sleep(0.5)
p.ChangeDutyCycle(10)
time.sleep(0.5)
p.ChangeDutyCycle(12.5)
time.sleep(0.5)
p.ChangeDutyCycle(10)
time.sleep(0.5)
p.ChangeDutyCycle(7.5)
time.sleep(0.5)
p.ChangeDutyCycle(5)
time.sleep(0.5)
p.ChangeDutyCycle(2.5)
time.sleep(0.5)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()