-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (51 loc) · 1.46 KB
/
app.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
from lib.L298N import L298N
from pyfirmata import Arduino
from flask import Flask, jsonify, request
app = Flask(__name__)
FALSE = 0
TRUE = 1
DELAY = 0.5
board = Arduino('/dev/ttyACM0')
# Initial pin
ena = 11
enb = 10
in1 = 7
in2 = 6
in3 = 5
in4 = 4
motor = L298N(board, ena, in1, in2, in3, in4, enb)
@app.route('/')
def home():
return 'What you look on here!!!'
@app.route('/forward')
def forward():
speed = float(request.args.get('speed'))
# if not speed.digit():
# return jsonify({'status': FALSE, 'message': 'Speed must digit'})
motor.forward(speed, DELAY)
return jsonify({'status': TRUE})
@app.route('/backward')
def backward():
speed = float(request.args.get('speed'))
# if not speed.digit():
# return jsonify({'status': FALSE, 'message': 'Speed must digit'})
motor.backward(speed, DELAY)
return jsonify({'status': TRUE})
@app.route('/left')
def left():
speed = float(request.args.get('speed'))
# if not speed.digit():
# return jsonify({'status': FALSE, 'message': 'Speed must digit'})
motor.turn_left(speed, DELAY)
return jsonify({'status': TRUE})
@app.route('/right')
def right():
speed = float(request.args.get('speed'))
# if not speed.digit():
# return jsonify({'status': FALSE, 'message': 'Speed must digit'})
motor.turn_right(speed, DELAY)
return jsonify({'status': TRUE})
@app.route('/stop')
def stop():
motor.full_stop(DELAY)
return jsonify({'status': DELAY})