-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotor.py
More file actions
37 lines (28 loc) · 980 Bytes
/
motor.py
File metadata and controls
37 lines (28 loc) · 980 Bytes
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
from flask import (render_template, Blueprint)
import RPi.GPIO as GPIO
import time
bp = Blueprint('motor', __name__, url_prefix='/motor')
MOTORPINS = {"pin1A": 36, "pin1B": 38, "pin1E":40}
GPIO.setmode(GPIO.BOARD)
GPIO.setup(MOTORPINS["pin1A"], GPIO.OUT)
GPIO.setup(MOTORPINS["pin1B"], GPIO.OUT)
GPIO.setup(MOTORPINS["pin1E"], GPIO.OUT)
@bp.route('/run',methods=["GET"])
def runMotor():
"""
This function runs the Motor
:return: the rendered template 'home.html'
"""
print "Inside run motor on"
try:
print "Turning motor on"
GPIO.output(MOTORPINS["pin1A"],GPIO.HIGH)
GPIO.output(MOTORPINS["pin1B"],GPIO.LOW)
GPIO.output(MOTORPINS["pin1E"],GPIO.HIGH)
time.sleep(10)
print "Stopping motor"
GPIO.output(MOTORPINS["pin1E"],GPIO.LOW)
finally:
GPIO.output(MOTORPINS["pin1E"],GPIO.LOW)
GPIO.cleanup()
return render_template('motor.html')