|
1 |
| -import network |
2 | 1 | from machine import Pin, SPI, ADC, I2C
|
3 |
| -import SSD1306 |
4 |
| -from max7219 import Max7219 |
| 2 | +import network |
| 3 | +import max7219 |
5 | 4 | import socket
|
| 5 | +import mrequests as requests |
| 6 | +from microdot import Microdot, Response |
| 7 | +import max7219 |
6 | 8 |
|
7 |
| -wlan = network.WLAN(network.STA_IF) |
8 |
| -wlan.active(True) |
9 |
| -if not wlan.isconnected(): |
10 |
| - # print('connecting to network...') |
11 |
| - # oled.fill(0) |
12 |
| - # oled.text('connecting to network...', 0, 10) |
13 |
| - # oled.show() |
14 |
| - while not wlan.isconnected(): |
15 |
| - pass |
16 |
| -# print('network config:', wlan.ifconfig()) |
17 |
| -# oled.fill(0) |
18 |
| -# oled.text('network config:', 0, 10) |
19 |
| -# oled.text(wlan.ifconfig()[0], 0, 20) |
20 |
| -# oled.show() |
21 |
| - |
22 |
| -# ESP32 Pin assignment |
23 |
| -# i2c = I2C(-1, scl=Pin(22), sda=Pin(21)) |
24 | 9 |
|
25 |
| -# oled_width = 128 |
26 |
| -# oled_height = 32 |
27 |
| -# oled = SSD1306.SSD1306_I2C(oled_width, oled_height, i2c) |
| 10 | +def matrixMessage(msg, slidervalue): |
| 11 | + spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(23)) |
| 12 | + ss = Pin(19, Pin.OUT) |
| 13 | + |
| 14 | + display = max7219.Matrix8x8(spi, ss, 12) |
| 15 | + display.fill(0) |
| 16 | + display.brightness(slidervalue) |
| 17 | + if not msg: |
| 18 | + # display.pixel(0,0,1) |
| 19 | + # display.pixel(1,1,1) |
| 20 | + # display.hline(0,4,8,1) |
| 21 | + # display.vline(4,0,8,1) |
| 22 | + # display.line(8, 0, 16, 8, 1) |
| 23 | + # display.rect(17,1,6,6,1) |
| 24 | + # display.fill_rect(25,1,6,6,1) |
| 25 | + display.show(msg,0,0,1) |
| 26 | + else: |
| 27 | + display.text(msg,0,0,1) |
| 28 | + display.show() |
28 | 29 |
|
29 |
| -# oled.text('Welcome', 0, 0) |
30 |
| -# oled.text('Starting up.....', 0, 20) |
31 | 30 |
|
32 |
| -#p4 = Pin(4, Pin.OUT) |
33 |
| -#p4.on() |
34 |
| - |
35 |
| - |
36 |
| -# def setup_screen(): |
37 |
| -# spi = SPI(1, baudrate=10000000, polarity=1, |
38 |
| -# phase=0, sck=Pin(19), mosi=Pin(23)) # SCK = cs mosi = din |
39 |
| -# cs = Pin(18, Pin.OUT) |
40 |
| -# screen = max7219.Max7219(32, 16, spi, cs) # Clk PIN (Display) |
41 |
| -# screen.brightness(10) |
42 |
| -# return screen |
| 31 | +if not wlan.isconnected(): |
| 32 | + while not wlan.isconnected(): |
| 33 | + pass |
43 | 34 |
|
44 |
| -# screen = setup_screen() |
45 |
| -# screen.text('Hi!', 4, 4, 1) |
46 |
| -# screen.show() |
| 35 | +app = Microdot() |
47 | 36 |
|
48 |
| -spi = SPI(1, |
49 |
| - baudrate=10000000, |
50 |
| - polarity=1, |
51 |
| - phase=0, |
52 |
| - sck=Pin(18), |
53 |
| - mosi=Pin(23)) |
54 |
| -cs = Pin(19, Pin.OUT) |
55 |
| -display = Max7219(32, 24, spi, cs) |
| 37 | +htmldoc = """<!DOCTYPE html> |
| 38 | +<html> |
| 39 | + <head> |
| 40 | + <title>Matrix Display</title> |
| 41 | + </head> |
| 42 | + <body> |
| 43 | + <div> |
| 44 | + <h1>Matrix Display</h1> |
| 45 | + <p>Enter your message</p> |
| 46 | + </div> |
| 47 | + <div> |
| 48 | + <form method="post"> |
| 49 | + <div class="form-group"> |
| 50 | + <label for="title">Message</label> |
| 51 | + <input type="text" name="mxmessage" |
| 52 | + placeholder="" class="form-control" |
| 53 | + value=""></input> |
| 54 | + </div> |
| 55 | + <div class="slidecontainer"> |
| 56 | + <label for="title">Brightness (<span id="slidervalue"></span>, 0 = dim)</label> |
| 57 | + <input type="range" name="brightness" min="0" max="15" value="0" class="slider" id="brightness"> |
| 58 | + </div> |
56 | 59 |
|
57 |
| -print('Loaded') |
58 |
| -display.brightness(15) |
59 |
| -display.rect(0, 0, 32, 24, 1) # Draws a frame |
60 |
| -display.text('abcd', 1, 1, 1) |
61 |
| -display.text('EFGH', 0, 8, 1) |
62 |
| -display.text('IJKL', 0, 16, 1) |
63 |
| -#display.marquee('Hello World!') |
| 60 | + <div class="form-group"> |
| 61 | + <button type="submit" class="btn btn-primary">Submit</button> |
| 62 | + </div> |
| 63 | + |
| 64 | + </form> |
| 65 | + </div> |
| 66 | + |
| 67 | + <script> |
| 68 | + var slider = document.getElementById("brightness"); |
| 69 | + var output = document.getElementById("slidervalue"); |
| 70 | + output.innerHTML = slider.value; |
64 | 71 |
|
65 |
| -display.show() |
| 72 | + slider.oninput = function() { |
| 73 | + output.innerHTML = this.value; |
| 74 | + matrixMessage(mxmessage,this.value); |
| 75 | + } |
| 76 | + </script> |
66 | 77 |
|
| 78 | + </body> |
| 79 | +</html> |
| 80 | +""" |
67 | 81 |
|
68 | 82 |
|
| 83 | +@app.route("", methods=["GET", "POST"]) |
| 84 | +def serial_number(request): |
| 85 | + print(request.headers) |
| 86 | + if request.method == 'POST': |
| 87 | + msg = request.form['mxmessage'] |
| 88 | + brightness = int(request.form['brightness']) |
| 89 | + if len(msg) == 0: |
| 90 | + print(msg) |
| 91 | + msg = wlan.ifconfig()[0][-3:] |
| 92 | + matrixMessage(msg,brightness) |
| 93 | + else: |
| 94 | + matrixMessage(msg,brightness) |
| 95 | + return Response(body=htmldoc, headers={"Content-Type": "text/html"}) |
69 | 96 |
|
| 97 | +app.run(debug=True) |
0 commit comments