Skip to content

Instantly share code, notes, and snippets.

@araemon araemon/servo.py
Created Nov 11, 2019

Embed
What would you like to do?
# -*- coding: utf-8 -*-
# python2で実行すること
import RPi.GPIO as GPIO
import time
import os
import signal
GPIO.setmode(GPIO.BCM)
SIG = 26
GPIO.setup(SIG, GPIO.OUT)
# PWMサイクル:20ms(=50Hz)
servo = GPIO.PWM(SIG, 50)
time.sleep(0.3)
servo.start(0)
servo.ChangeDutyCycle(6.3) #
time.sleep(1.0)
for i in range(5):
servo.ChangeDutyCycle(2.2) #
time.sleep(1.0)
servo.ChangeDutyCycle(10.8) # 180°
time.sleep(1.0)
servo.ChangeDutyCycle(6.3) # 90°
time.sleep(1.0)
servo.stop()
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.