forked from donskytech/micropython-raspberry-pi-pico
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpicow_wifi_neopixel_color_wheel.py
74 lines (64 loc) · 2.02 KB
/
picow_wifi_neopixel_color_wheel.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
import myWifi
from machine import Pin
from neopixel import NeoPixel
numP = 10
neo_pin = Pin(16, Pin.OUT)
pixels = NeoPixel(neo_pin, numP)
def webpage():
#Template HTML
html = f"""
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@jaames/iro@5"></script>
</head>
<body>
<h1 style="text-align:center;">Please choose your Neopixel Color</h1>
<div id="picker" style= "margin:auto;width:50%;"></div>
<br>
<h2 id="values" style="color:blue;text-align:center;" ></h2>
</body>
<script>
var colorPicker = new iro.ColorPicker('#picker', {{
width: 280,
wheelLightness: false,
color: "rgb(255, 0, 0)",
borderWidth: 5,
borderColor: "#000",
}});
colorPicker.on('input:end', function(color) {{
values.innerHTML = color.rgbString;
var xhr = new XMLHttpRequest();
xhr.open("GET", color.rgbString, true);
xhr.send();
}});
</script>
</html>
"""
return str(html)
def serve(connection):
global demo_number
#Start a web server
while True:
client = connection.accept()[0]
request = client.recv(1024)
request = str(request)
print (request)
try:
request = request.split()[1]
except IndexError:
pass
print (request)
if '/rgb' in request:
color_str = request[5:-1]
print (color_str)
color_tuple = tuple(map(int, color_str.split(',%20')))
print (color_tuple)
pixels.fill(color_tuple)
pixels.write()
html = webpage()
client.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
client.send(html)
client.close()
connection = myWifi.connect()
serve(connection)