-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
61 lines (52 loc) · 1.27 KB
/
run.py
File metadata and controls
61 lines (52 loc) · 1.27 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
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask
from flask import render_template
import RPi.GPIO as GPIO
from Raspi_MiniMoto_Driver import MOTO
import time
MY_GPIO_18 = 18
motor1 = MOTO(0x60)
motor2 = MOTO(0x65)
app = Flask(__name__)
@app.route("/")
def hello(name=None):
return render_template('index.html', name=name)
@app.route("/led/<On_Off>")
def led_on_off(On_Off):
GPIO.setmode(GPIO.BCM)
GPIO.setup(MY_GPIO_18, GPIO.OUT)
if On_Off == 'on':
GPIO.output(MY_GPIO_18, GPIO.HIGH)
return 'LED ON!!'
elif On_Off == 'off':
GPIO.output(MY_GPIO_18, GPIO.LOW)
GPIO.cleanup()
return 'LED OFF!!'
else:
GPIO.cleanup()
return 'Invalid argument!'
@app.route('/ledoff')
def led_off():
GPIO.setmode(GPIO.BCM)
GPIO.setup(MY_GPIO_18, GPIO.OUT)
return 'LED OFF!!'
@app.route('/motors_con/<Left_Right>')
def motors_con(Left_Right):
L_R = Left_Right.split("+")
iL = int(L_R[0])
iR = int(L_R[1])
if iL > 0:
motor1.drive(40)
elif iL < 0:
motor1.drive(-40)
else:
motor1.brake()
if iR > 0:
motor2.drive(40)
elif iR < 0:
motor2.drive(-40)
else:
motor2.brake()
return Left_Right
if __name__ == "__main__":
app.debug = True
app.run('0.0.0.0')