-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
201 lines (170 loc) · 4.84 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from flask import Flask, render_template, request
import json
#import mysql.connector
#import RPi.GPIO as GPIO
import time
app = Flask(__name__)
"""
GPIO.setmode(GPIO.BCM)
#horizontal motor setup
HORIZ_POWER = ?
HORIZ_GROUND = ?
HORIZ_ENA = 4
HORIZ_RIGHT = 14
HORIZ_LEFT = 15
GPIO.setup(HORIZ_RIGHT, GPIO.OUT)
GPIO.setup(HORIZ_LEFT, GPIO.OUT)
GPIO.setup(HORIZ_ENA, GPIO.OUT)
GPIO.output(HORIZ_RIGHT, GPIO.LOW)
GPIO.output(HORIZ_LEFT, GPIO.LOW)
horiz_PWM = GPIO.PWM(HORIZ_ENA, 100)
horiz_PWM.start(0)
#vertical motor setup
VERT_POWER = ?
VERT_GROUND = ?
VERT_ENA = 17
VERT_UP = 27
VERT_DOWN = 18
GPIO.setup(VERT_UP, GPIO.OUT)
GPIO.setup(VERT_DOWN, GPIO.OUT)
GPIO.setup(VERT_ENA, GPIO.OUT)
GPIO.output(VERT_UP, GPIO.LOW)
GPIO.output(VERT_DOWN, GPIO.LOW)
vert_PWM = GPIO.PWM(VERT_ENA, 100)
vert_PWM.start(0)
#string motor setup
STRING_POWER = ?
STRING_GROUND = ?
STRING_ENA = ?
STRING_UP = ?
STRING_DOWN = ?
GPIO.setup(STRING_UP, GPIO.OUT)
GPIO.setup(STRING_DOWN, GPIO.OUT)
GPIO.setup(STRING_ENA, GPIO.OUT)
GPIO.output(STRING_UP, GPIO.LOW)
GPIO.output(STRING_DOWN, GPIO.LOW)
string_PWM = GPIO.PWM(STRING_ENA, 100)
string_PWM.start(0)
DIR_FORWARD = 0
DIR_BACKWARD= 1
def motorStop():
GPIO.output(HORIZ_RIGHT, GPIO.LOW)
GPIO.output(HORIZ_LEFT, GPIO.LOW)
GPIO.output(HORIZ_ENA, GPIO.LOW)
GPIO.output(VERT_UP, GPIO.LOW)
GPIO.output(VERT_DOWN, GPIO.LOW)
GPIO.output(VERT_ENA, GPIO.LOW)
GPIO.output(STRING_UP, GPIO.LOW)
GPIO.output(STRING_DOWN, GPIO.LOW)
GPIO.output(STRING_ENA, GPIO.LOW)
GPIO.cleanup()
def motorHorizontal(direction):
if direction == DIR_FORWARD:
GPIO.output(HORIZ_RIGHT, GPIO.HIGH)
GPIO.output(HORIZ_LEFT, GPIO.LOW)
horiz_PWM.start(100)
horiz_PWM.ChangeDutyCycle(speed) Might not use this
elif direction == DIR_BACKWARDS:
GPIO.output(HORIZ_RIGHT, GPIO.LOW)
GPIO.output(HORIZ_LEFT, GPIO.HIGH)
horiz_PWM.start(0)
horiz_PWM.ChangeDutyCycle(speed) might not use this
def motorVertical(direction):
if direction == DIR_FORWARD:
GPIO.output(VERT_UP, GPIO.HIGH)
GPIO.output(VERT_DOWN, GPIO.LOW)
vert_PWM.start(100)
vert_PWM.ChangeDutyCycle(speed) Might not use this
elif direction == DIR_BACKWARDS:
GPIO.output(VERT_UP, GPIO.LOW)
GPIO.output(VERT_DOWN, GPIO.HIGH)
vert_PWM.start(0)
vert_PWM.ChangeDutyCycle(speed) might not use this
"""
#main route
#================================
#startup
@app.route("/", methods=["GET"])
def homeStartup():
return render_template("index.html", title="index", name="Ty Allembert")
#Index
@app.route("/index.html", methods=["GET"])
def homeIndex():
return render_template("index.html", title="index", name="Ty Allembert")
#Leaderboard
@app.route("/leaderboard.html", methods=["GET"])
def homeLeaderboard():
"""database = mysql.connector.connect(
host=credentials["host"],
user=credentials["user"],
passwd=credentials["password"],
database=credentials["database"]
)
cursor = database.cursor()
# Your query to return records with ID 20 through 30 [inclusive]
# from the test_data table
query = "SELECT * FROM finalProject;"
cursor.execute(query)
data = cursor.fetchall()
cursor.close()
database.close()"""
return render_template("leaderboard.html", title="Leaderboard", name="Ty Allembert")
#How to play
@app.route("/howToPlay.html", methods=["GET"])
def homeHowTo():
return render_template("howToPlay.html", title="How to Play", name="Ty Allembert")
#================================
#Motors
#================================
#stop motor
@app.route("/stop_motor", methods=["POST"])
def stop_motor():
print("stopped")
#make arm go up
#motorStop()
return "stopped"
#vertical arm up
@app.route("/vertical_up", methods=["POST"])
def vertical_up():
print("up")
#make arm go up
#motorVertical(1)
return "up"
#vertical arm down
@app.route("/vertical_down", methods=["POST"])
def vertical_down():
print("down")
#make arm go down
#motorVertical(0)
return "down"
#horizontal spin right
@app.route("/horizontal_right", methods=["POST"])
def horizontal_right():
print("right")
#make motor spin right
#motorHorizontal(1);
return "right"
#horizontal spin left
@app.route("/horizontal_left", methods=["POST"])
def horizontal_left():
print("left")
#make motor spin left
#motorHorizontal(0)
return "left"
#========String Motor==========
#String up
@app.route("/string_up", methods=["POST"])
def string_up():
print("String up")
#make motor spin left
#string_PWM.ChangeDutyCycle(10)
#GPIO.cleanup()
return "String up"
#String down
@app.route("/string_down", methods=["POST"])
def string_down():
print("String down")
#make motor spin left
#hstring_PWM.ChangeDutyCycle(10)
#GPIO.cleanup()
return "String down"