-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
40 lines (28 loc) · 854 Bytes
/
app.py
File metadata and controls
40 lines (28 loc) · 854 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
38
39
40
from flask import Flask, render_template, request
import board
import neopixel
app = Flask(__name__)
num_pixels = 100
pixel_pin = board.D18
ORDER = neopixel.RGB
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER
)
def setlight(colourin):
pixels.fill((0, 0, 0))
pixels.show()
pixels.fill(colourin)
pixels.show()
app = Flask(__name__)
def hex_to_rgb(value):
value = value.lstrip("#")
lv = len(value)
return tuple(int(value[i : i + lv // 3], 16) for i in range(0, lv, lv // 3))
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
colour = request.form["colour_in"]
setlight(hex_to_rgb(colour))
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0",port=80)