-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolourPickerWeb.lua
More file actions
38 lines (31 loc) · 1.86 KB
/
colourPickerWeb.lua
File metadata and controls
38 lines (31 loc) · 1.86 KB
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
--Web page setup
web=net.createServer(net.TCP)
web:listen(80,function(conn)
conn:on("receive", function(client,request)
body = "<h1>Colour Controller</h1>";
--Determine if a changeColours has been sent to us
colourChange = {string.match(request,"GET.*changeColours.Picker.*23(%x%x%x%x%x%x).*HTTP.*")};
if colourChange ~= nil and #colourChange > 0 then
--Postback need to use new colours
pickerHex = "#" .. colourChange[1]; --The input control expects a prefixed #
--Split and convert pickerHex to RGB decimal values for determining the PWM duty values
red = tonumber(string.sub(pickerHex,2,3),16);
green = tonumber(string.sub(pickerHex,4,5),16);
blue = tonumber(string.sub(pickerHex,6,7),16);
--Update the RGB LED's using the pwmConversionFactor
setRGB(redPin, red * pwmConversionFactor, greenPin, green * pwmConversionFactor, bluePin, blue * pwmConversionFactor);
else
--Get the PWM Colour code
pwmValues = readRGBValue(redPin, greenPin, bluePin);
--Reverse pwmConversionFactor (to get true RGB values) and convert to Hex for pickerHex
pickerHex = "#" .. valueToHexRgb(pwmValues.red, pwmConversionFactor) .. valueToHexRgb(pwmValues.green, pwmConversionFactor) .. valueToHexRgb(pwmValues.blue, pwmConversionFactor);
end
body = body.."<form action='changeColours'>"
body = body.."<input type='color' name='Picker' id='html5colorpicker' onchange='clickColor(0, -1, -1, 5)' value='" .. pickerHex .. "' style='width:500;height:500;'><br/><br/>";
body = body.."<input type='submit' value='Submit' style='width:500;height:250;'>"
body = body.."</form>"
client:send(body);
client:close();
collectgarbage();
end)
end)