-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSmart_Home.js
157 lines (126 loc) · 3.92 KB
/
Smart_Home.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const gaugeElement = document.querySelector(".gauge");
function setGaugeValue(gauge, value) {
if (value < 0 || value > 1) {
return;
}
gauge.querySelector(".gauge__fill").style.transform = `rotate(${value / 2}turn)`;
gauge.querySelector(".gauge__cover").textContent = `${Math.round(value * 100)}%`;
}
setGaugeValue(gaugeElement, 0.6);
function light1() {
let lightswitch1 = document.getElementById("lightswitch1");
let lightimg1 = document.getElementById("lightimg1");
let lighton1 = document.getElementById("lighton1");
if (lightswitch1.checked === true) {
lightimg1.style.display = "none";
lighton1.style.display = "block";
}
else {
lightimg1.style.display = "block";
lighton1.style.display = "none";
}
}
function light2() {
let lightswitch2 = document.getElementById("lightswitch2");
let lightimg2 = document.getElementById("lightimg2");
let lighton2 = document.getElementById("lighton2");
if (lightswitch2.checked === true) {
lightimg2.style.display = "none";
lighton2.style.display = "block";
}
else {
lightimg2.style.display = "block";
lighton2.style.display = "none";
}
}
function light3() {
let lightswitch3 = document.getElementById("lightswitch3");
let lightimg3 = document.getElementById("lightimg3");
let lighton3 = document.getElementById("lighton3");
if (lightswitch3.checked === true) {
lightimg3.style.display = "none";
lighton3.style.display = "block";
}
else {
lightimg3.style.display = "block";
lighton3.style.display = "none";
}
}
function bedlamp1() {
let bedlampswitch1 = document.getElementById("bedlampswitch1");
let bedlampimg1 = document.getElementById("bedlampimg1");
let bedlampon1 = document.getElementById("bedlampon1");
if (bedlampswitch1.checked === true) {
bedlampimg1.style.display = "none";
bedlampon1.style.display = "block";
}
else {
bedlampimg1.style.display = "block";
bedlampon1.style.display = "none";
}
}
let fanswitch1 = document.getElementById("fanswitch1");
let fan1 = document.getElementById("fan1");
let fanswitch2 = document.getElementById("fanswitch2");
let fan2 = document.getElementById("fan2");
let fanswitch3 = document.getElementById("fanswitch3");
let fan3 = document.getElementById("fan3");
let fanswitch4 = document.getElementById("fanswitch4");
let fan4 = document.getElementById("fan4");
function fanrotate1() {
if (fanswitch1.checked === true) {
fan1.className += " rotate";
}
else {
fan1.className -= " rotate";
}
}
function fanrotate2() {
if (fanswitch2.checked === true) {
fan2.className += " rotate";
}
else {
fan2.className -= " rotate";
}
}
function fanrotate3() {
if (fanswitch3.checked === true) {
fan3.className += " rotate";
}
else {
fan3.className -= " rotate";
}
}
function fanrotate4() {
if (fanswitch4.checked === true) {
fan4.className += " rotate";
}
else {
fan4.className -= " rotate";
}
}
function startTime() {
let today = new Date();
let day = today.getDate();
let month = today.getMonth() + 1;
let year = today.getFullYear();
let h = today.getHours();
let m = today.getMinutes();
let s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
let options = {
hour: 'numeric',
minute: 'numeric',
hour12: true
};
let timeString = today.toLocaleString('en-US', options);
document.getElementById('date').innerHTML = day + "/" + month + "/" + year;
// document.getElementById('time').innerHTML = h + ":" + m;
document.getElementById('time').innerHTML = timeString;
let t = setTimeout(function () { startTime() }, 500);
}
function checkTime(i) {
if (i < 10) { i = "0" + i }; // add zero in front of numbers < 10
return i;
}