Code
Code
py @ 5 : 1
led = LED(2)
led2 = LED(20)
led3 = LED(4)
led4 = LED(21)
app = Flask(__name__, static_url_path = "", static_folder = "static")
@app.route("/")
def index():
return render_template("home.html")
@app.route("/light")
def changetolight():
return render_template("homeinterface.html")
@app.route("/openliving")
def openliving():
led.on()
return render_template("homeinterface.html")
@app.route("/closeliving")
def closeliving():
led.off()
return render_template("homeinterface.html")
@app.route("/openwaterroom")
def openwaterroom():
led2.on()
return render_template("homeinterface.html")
@app.route("/closewaterroom")
def closewaterroom():
led2.off()
return render_template("homeinterface.html")
@app.route("/openfoodroom")
def openfoodroom():
led3.on()
return render_template("homeinterface.html")
@app.route("/closefoodroom")
def closefoodroom():
led3.off()
return render_template("homeinterface.html")
@app.route("/openbedroom")
def openbedroom():
led4.on()
return render_template("homeinterface.html")
@app.route("/closebedroom")
def closebedroom():
led4.off()
return render_template("homeinterface.html")
try:
if __name__== "__main__":
app.run()
finally:
led.off()
led2.off()
led3.off()
led4.off()
home.html
<html>
<head>
<script>
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
function ChangeNightmode() {
document.body.style.backgroundColor = "#4E6B8C";
}
function ChangeSavemode() {
document.body.style.backgroundColor = "#A8E8A3";
}
</script>
<title>Page Title</title>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
<body bgcolor="#D29D56">
</body>
<table align="center"; border="1">
<tr>
<td align="center">
<button type="button" onclick="alert('Routine For Today !')"><img
src="https://png.icons8.com/metro/1600/sun.png" alt="HTML5 Icon" width="90" height="85"
/></button></td>
<td align="center">
<a href="/lock">
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/18799-200.png" alt="HTML5 Icon"
width="90" height="85" /></a></td>
<td align="center">
<a href="/air">
<img src="https://cdn3.iconfinder.com/data/icons/tools-solid-icons-vol-1/72/29-512.png"
alt="HTML5 Icon" width="90" height="85" /></a></td>
<td align="center">
<a href="/light">
<img
src="http://icons.iconarchive.com/icons/pixelkit/swanky-outlines/256/15-Light-Bulb-icon.png"
alt="HTML5 Icon" width="90" height="85" /></a></td>
<td>
<a href="/alarm">
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/326193-200.png" alt="HTML5 Icon"
width="90" height="85"/></a></td>
</tr>
<tr>
<td>
<a href="music">
<img src="https://png.icons8.com/metro/1600/music.png" alt="HTML5 Icon" width="90"
height="85" /></a></td>
<td>
<button type="button" onclick="ChangeNightmode()"><img
src="https://d30y9cdsu7xlg0.cloudfront.net/png/595-200.png" alt="HTML5 Icon" width="80"
height="85"/></button></td>
<td>
<a href="door">
<img src="https://cdn1.iconfinder.com/data/icons/door-3/200/1334-512.png" alt="HTML5
Icon" width="80" height="85"/></a></td>
<td>
<a href="home">
<img src="http://riversinsgroup.com/wp-content/uploads/home-home-icon-80046.png"
alt="HTML5 Icon" width="80" height="85"/></a></td>
<td>
<button type="button" onclick="ChangeSavemode()"><img
src="https://d30y9cdsu7xlg0.cloudfront.net/png/394900-200.png" width="80"
height="85"/></td>
</td>
</table>
</html>
homeinterface.html
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
th {
text-align: left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 70px;
background-color: #f1f1f1;
}
li a {
display: block;
color: #000;
padding: 4px 12px;
text-decoration: none;
}
</body>
</html>