-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwmsOne.py
executable file
·125 lines (105 loc) · 3.57 KB
/
pwmsOne.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/python3
from Servo import *
from time import sleep
#from flask import Flask, render_template
# create instance of ServoCtrl on i2c bus 2 at address 64 using 60hz pwm frequency.
# change 64 to 0x7f for servo cape
servos = ServoCtrl("/dev/bone/i2c/2", 0x7f, 50)
# add a servo to controller, using channel 0. servo max rotation is 90 degrees;
servos.add_servo("1a", 0, 180)
# add a servo to controller, using channel 15. servo max rotation is 90 degrees;
servos.add_servo("1b", 1, 180)
servos.enablePWMs("0")
#servos.add_servo("2c", 3, 180)
#servos.add_servo("2d", 4, 180)
#servos.add_servo("3e", 6, 180)
#servos.add_servo("3f", 7, 180)
#servos.add_servo("4g", 9, 180)
#servos.add_servo("4h", 10, 180)
#servos.enablePWMs(True)
#pwm_controller.set_pwm_frequency(50)
#app = Flask(__name__)
#@app.route('/')
#@app.route('/<state>')
try:
arch = str(input("Please enter a value of max, zero, or half...: "))
while True:
# for i in range(0, 35, 1):
if arch == "zero":
servos.enablePWMs("1")
servos.set_servo_angle("1a", 0)
sleep(1)
servos.set_servo_angle("1b", 0)
sleep(1)
# servos.set_servo_angle("2c", 0)
# sleep(1)
# servos.set_servo_angle("2d", 0)
# sleep(1)
# servos.set_servo_angle("3e", 0)
# sleep(1)
# servos.set_servo_angle("3f", 0)
# sleep(1)
# servos.set_servo_angle("4g", 0)
# sleep(1)
# servos.set_servo_angle("4h", 0)
# sleep(1)
# servos.set_servo_angle("another servo",servos.get_servo_max_angle("another servo")/2)
# Set the servo(s) to halfway of angle 0...
# if state == "50":
elif arch == "half":
servos.enablePWMs("1")
servos.set_servo_percent("1a", 50)
sleep(1)
servos.set_servo_percent("1b", 50)
sleep(1)
# servos.set_servo_percent("2c", 50)
# sleep(1)
# servos.set_servo_percent("2d", 50)
# sleep(1)
# servos.set_servo_percent("3e", 50)
# sleep(1)
# servos.set_servo_percent("3f", 50)
# sleep(1)
# servos.set_servo_percent("4g", 50)
# sleep(1)
# servos.set_servo_percent("4h", 50)
# sleep(1)
# move servo3 to max rotation of 90 degrees
#if state == "max":
elif arch == "max":
servos.enablePWMs("1")
servos.set_servo_percent("1a", 180)
sleep(1)
servos.set_servo_percent("1b", 180)
sleep(1)
# servos.set_servo_percent("2c", 180)
# sleep(1)
# servos.set_servo_percent("2d", 180)
# sleep(1)
# servos.set_servo_percent("3e", 180)
# sleep(1)
# servos.set_servo_percent("3f", 180)
# sleep(1)
# servos.set_servo_percent("4g", 180)
# sleep(1)
# servos.set_servo_percent("4h", 180)
# sleep(1)
# servos.set_servo_angle("1a", servos.get_servo_max_angle("1a"))
# sleep(1)
# servos.set_servo_angle("1b", servos.get_servo_max_angle("1b"))
# sleep(1)
# Stop everything moving for good!
# if state == "stop":
# servos.enablePWMs(False)
# sleep(1)
# template_data = {
# "title" : state,
# }
# return render_template("ServoOne.html", **template_data)
else:
servos.enablePWMs("0")
#if __name__ == "__main__":
# app.run(host="0.0.0.0", port=5000, debug=True)
except KeyboardInterrupt:
servos.enablePWMs("0")
print("Done for now...")