0% found this document useful (0 votes)
15 views2 pages

3-RGB Led

Uploaded by

mysticpatel20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

3-RGB Led

Uploaded by

mysticpatel20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3-RGB LED

Flask_app.py:
from flask import Flask,render_template,request
app = Flask(_name_)

@app.route('/')
def RGB_LED():
return render_template("home.html")

@app.route('/led_data')
def led_data():
f = open("mysite/led_data", "r")
data=f.read()
return data

@app.route('/update_rgb')
def update_rgb():
r = request.args.get("red")
g = request.args.get("green")
b = request.args.get("blue")

x=r+':'+g+':'+b
f=open("mysite/led_data","w")
f.write(x)
return 'LED data updated successfully!'
Home.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RGB Color Picker</title>
</head>
<body>
<h1>RGB Color Picker</h1>
<form action="update_rgb">
Red: <input type="range" name="red" min="0" max="255" value="255"
oninput="updateColor()"><br>
Green: <input type="range" name="green" min="0" max="255" value="174"
oninput="updateColor()"><br>
Blue: <input type="range" name="blue" min="0" max="255" value="71"
oninput="updateColor()"><br>
<div id="colorBox" style="width: 100px; height: 100px; border: 1px solid #000; margin-top:
20px;"></div><br>
<button type="submit">Update</button>
</form>

<script>
function updateColor() {
var red = document.querySelector('input[name="red"]').value;
var green = document.querySelector('input[name="green"]').value;
var blue = document.querySelector('input[name="blue"]').value;

document.getElementById('colorBox').style.backgroundColor = 'rgb(' + red + ',' + green +


',' + blue + ')';
}
updateColor();
</script>
</body>
</html>

You might also like