-
Notifications
You must be signed in to change notification settings - Fork 0
/
14-2.py
43 lines (34 loc) · 931 Bytes
/
14-2.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
from flask import Flask
from flask import render_template
from flask import jsonify
import random
import rcpy.button as rc_button
from flask import request
import rcpy.led as rc_led
app = Flask(__name__)
@app.route('/')
def hello_world() :
return 'Hello World!'
@app.route('/page')
def page() :
return render_template("hi.html", value = "hello.py")
@app.route('/random')
def random_num() :
return jsonify(random_value = random.random())
@app.route('/button')
def button() :
return jsonify(
btn1 = rc_button.mode.is_pressed(),
btn2 = rc_button.pause.is_pressed()
)
@app.route("/led", methods=["POST"])
def led() :
print(request.form['led'])
led_num = request.form['led']
if led_num == '1' :
rc_led.red.toggle()
elif led_num == '2' :
rc_led.green.toggle()
return led_num
if __name__ == "__main__" :
app.run(host = "0.0.0.0")