-
Notifications
You must be signed in to change notification settings - Fork 51
/
arm.py
48 lines (34 loc) · 1.23 KB
/
arm.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
#!/usr/bin/python
from flask import Flask, render_template, request, Response, send_file
import os
import atexit
from Adafruit_PWM_Servo_Driver import PWM
import time
pwm = PWM(0x40, debug=True)
servoMin = 150 # Min pulse length out of 4096
servoMax = 600 # Max pulse length out of 4096
pwm.setPWMFreq(60) # Set frequency to 60 Hz
app = Flask(__name__)
def setServoPulse(channel, pulse):
pulseLength = 1000000 # 1,000,000 us per second
pulseLength /= 60 # 60 Hz
print "%d us per period" % pulseLength
pulseLength /= 4096 # 12 bits of resolution
print "%d us per bit" % pulseLength
pulse *= 1000
pulse /= pulseLength
pwm.setPWM(channel, 0, pulse)
@app.route("/")
def main():
return render_template('arm.html')
@app.route('/slider')
def slider():
num = int(request.args.get('num'))
value = int(request.args.get('value'))
print("%i %i" % (num, value))
fraction = int(servoMin + (value/100.0)*(servoMax - servoMin))
print("Setting servo to %i" % fraction)
pwm.setPWM(num, 0, fraction)
return ""
if __name__ == "__main__":
app.run()