-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
46 lines (37 loc) · 848 Bytes
/
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
import flask
import time
import unicornhat as unicorn
app = flask.Flask(__name__)
app.config["DEBUG"] = False
# Defaults
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(0)
unicorn.brightness(0.8)
width,height=unicorn.get_shape()
def setColor(r,g,b):
unicorn.clear()
unicorn.set_all(r,g,b)
unicorn.show()
# Define some endpoints for each color
@app.route('/red', methods=['GET'])
def red():
setColor(255,45,0)
return 'Red'
@app.route('/yellow', methods=['GET'])
def yellow():
setColor(255,253,0)
return 'Yellow'
@app.route('/green', methods=['GET'])
def green():
setColor(0,224,55)
return 'Green'
@app.route('/blue', methods=['GET'])
def blue():
setColor(1,17,213)
return 'Blue'
@app.route('/off', methods=['GET'])
def off():
unicorn.off()
return 'Off'
# Run the server
app.run(host='0.0.0.0',port='5000')