-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (82 loc) · 2.96 KB
/
main.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
from machine import Pin, SPI, ADC, I2C
import network
import max7219
import socket
import mrequests as requests
from microdot import Microdot, Response
import max7219
def matrixMessage(msg, slidervalue):
spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(23))
ss = Pin(19, Pin.OUT)
display = max7219.Matrix8x8(spi, ss, 12)
display.fill(0)
display.brightness(slidervalue)
if not msg:
# display.pixel(0,0,1)
# display.pixel(1,1,1)
# display.hline(0,4,8,1)
# display.vline(4,0,8,1)
# display.line(8, 0, 16, 8, 1)
# display.rect(17,1,6,6,1)
# display.fill_rect(25,1,6,6,1)
display.show(msg,0,0,1)
else:
display.text(msg,0,0,1)
display.show()
if not wlan.isconnected():
while not wlan.isconnected():
pass
app = Microdot()
htmldoc = """<!DOCTYPE html>
<html>
<head>
<title>Matrix Display</title>
</head>
<body>
<div>
<h1>Matrix Display</h1>
<p>Enter your message</p>
</div>
<div>
<form method="post">
<div class="form-group">
<label for="title">Message</label>
<input type="text" name="mxmessage"
placeholder="" class="form-control"
value=""></input>
</div>
<div class="slidecontainer">
<label for="title">Brightness (<span id="slidervalue"></span>, 0 = dim)</label>
<input type="range" name="brightness" min="0" max="15" value="0" class="slider" id="brightness">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<script>
var slider = document.getElementById("brightness");
var output = document.getElementById("slidervalue");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
matrixMessage(mxmessage,this.value);
}
</script>
</body>
</html>
"""
@app.route("", methods=["GET", "POST"])
def serial_number(request):
print(request.headers)
if request.method == 'POST':
msg = request.form['mxmessage']
brightness = int(request.form['brightness'])
if len(msg) == 0:
print(msg)
msg = wlan.ifconfig()[0][-3:]
matrixMessage(msg,brightness)
else:
matrixMessage(msg,brightness)
return Response(body=htmldoc, headers={"Content-Type": "text/html"})
app.run(debug=True)