Skip to content
Browse files

Create Adafruit_Servo.py

  • Loading branch information...
1 parent fd4f5be commit ae33202fa1895c2caea6f99b313c01b314ee3bfa @videoman committed Jun 13, 2013
Showing with 29 additions and 0 deletions.
  1. +29 −0 Adafruit_Servo.py
View
29 Adafruit_Servo.py
@@ -0,0 +1,29 @@
+# Servo Control
+import time
+def set(property, value):
+ try:
+ f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
+ f.write(value)
+ f.close()
+ except:
+ print("Error writing to: " + property + " value: " + value)
+
+
+def setServo(angle):
+ set("servo", str(angle))
+
+
+set("delayed", "0")
+set("mode", "servo")
+set("servo_max", "180")
+set("active", "1")
+
+delay_period = 0.01
+
+while True:
+ for angle in range(0, 180):
+ setServo(angle)
+ time.sleep(delay_period)
+ for angle in range(0, 180):
+ setServo(180 - angle)
+ time.sleep(delay_period)

0 comments on commit ae33202

Please sign in to comment.
Something went wrong with that request. Please try again.