forked from MakersTeam/Edison
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSweep.py
More file actions
48 lines (36 loc) · 1.04 KB
/
Sweep.py
File metadata and controls
48 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
"""
Sweep.py
This example shows how to use a servo motor attached to a PWM pin.
This example code is in the public domain.
Revision History
----------------------------------------------------------
Author Date Description
----------------------------------------------------------
Diego Villalobos 02-12-2015 Example created
"""
# Libraries required
from Servo import *
import time
# Create a new servo object with a reference name
myServo = Servo("First Servo")
# Attaches the servo to pin 3 in Arduino Expansion board
myServo.attach(3)
# Print servo settings
print ""
print "*** Servo Initial Settings ***"
print myServo
print ""
try:
# Sweeps the servo motor forever
while True:
# From 0 to 180 degrees
for angle in range(0,180):
myServo.write(angle)
time.sleep(0.005)
# From 180 to 0 degrees
for angle in range(180,-1,-1):
myServo.write(angle)
time.sleep(0.005)
except KeyboardInterrupt:
print "Sweep ended."