-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
223 lines (188 loc) · 7.62 KB
/
index.html
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head>
<title>Temperature Control App</title>
<style>
/* CSS styles for the UI */
/* Add your own styling here */
body {
background-image: url('background-image.jpg');
background-repeat: no-repeat;
background-size: cover;
font-family: Arial, sans-serif;
}
h1 {
color: #333;
}
h2 {
color: #666;
}
#temperature {
font-weight: bold;
font-size: 24px;
}
label {
font-weight: bold;
}
input[type="number"],
input[type="range"] {
width: 150px;
margin-bottom: 10px;
}
button {
padding: 8px 16px;
background-color: #007bff;
border: none;
color: #fff;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
/* Additional styling for the congratulatory GIF */
#congratsGif {
position: fixed;
top: 20px;
right: 20px;
max-width: 200px;
}
</style>
</head>
<body>
<h1>Temperature Control App</h1>
<div>
<h2>Current Temperature: <span id="temperature"></span>°C</h2>
<label for="thresholdTemperature">Set Temperature Threshold: </label>
<input type="number" id="thresholdTemperature" placeholder="Enter threshold temperature">
<button onclick="setThresholdsAndCheck()">Set</button>
</div>
<div>
<h2>Fan Control</h2>
<label for="fanValue">Fan Speed: </label>
<input type="number" id="fanValue" readonly>
<input type="range" id="fanSpeed" min="0" max="100" oninput="updateFanSpeed(this.value)">
</div>
<div>
<h2>Light Control</h2>
<label for="lightValue">Light Brightness: </label>
<input type="number" id="lightValue" readonly>
<input type="range" id="lightBrightness" min="0" max="100" oninput="updateLightBrightness(this.value)">
</div>
<audio id="buzzerSound" src="" loop></audio>
<script>
let temperatureThreshold = 250;
let fanThreshold = 80;
let lightThreshold = 50;
// Function to update temperature
function updateTemperature(temperature) {
const temperatureElement = document.getElementById('temperature');
temperatureElement.innerText = temperature;
// Check if temperature exceeds the threshold
if (temperature > temperatureThreshold) {
// Start playing the buzzer sound continuously
playBuzzerSound();
} else {
// Stop playing the buzzer sound
stopBuzzerSound();
}
// Adjust the light brightness based on the time of day
adjustBrightness();
}
// Function to play the buzzer sound
function playBuzzerSound() {
const buzzerSound = document.getElementById('buzzerSound');
buzzerSound.src = "buzz-sound.mp3";
buzzerSound.play();
// Display an alert to reduce values
alert('Temperature threshold exceeded! Reduce fan speed and light brightness.');
}
// Function to stop playing the buzzer sound
function stopBuzzerSound() {
const buzzerSound = document.getElementById('buzzerSound');
buzzerSound.pause();
buzzerSound.src = "";
}
// Function to set threshold values and check if values exceed thresholds
function setThresholdsAndCheck() {
const thresholdTemperatureInput = document.getElementById('thresholdTemperature');
temperatureThreshold = parseInt(thresholdTemperatureInput.value) || 250;
checkThresholds();
// Display a popup message for threshold value setting
alert('Threshold values set successfully!');
displayThumbsGif();
}
// Function to check if values exceed thresholds
function checkThresholds() {
const fanValue = parseInt(document.getElementById('fanValue').value) || 0;
const lightValue = parseInt(document.getElementById('lightValue').value) || 0;
if (fanValue > fanThreshold || lightValue > lightThreshold) {
playBuzzerSound();
} else {
stopBuzzerSound();
// Check if the congratulatory GIF is already displayed
const congratsGif = document.getElementById('congratsGif');
if (!congratsGif) {
// Display a congratulatory GIF
displayCongratsGif();
}
}
}
// Function to update fan speed
function updateFanSpeed(speed) {
const fanValueInput = document.getElementById('fanValue');
fanValueInput.value = speed;
checkThresholds();
}
// Function to update light brightness
function updateLightBrightness(brightness) {
const lightValueInput = document.getElementById('lightValue');
lightValueInput.value = brightness;
checkThresholds();
}
// Function to adjust the light brightness based on the time of day
function adjustBrightness() {
const lightBrightnessInput = document.getElementById('lightBrightness');
const currentDate = new Date();
const currentHour = currentDate.getHours();
// Adjust the light brightness based on the time of day
if (currentHour >= 6 && currentHour <= 18) {
lightBrightnessInput.value = 50; // Set lower brightness during the day
} else {
lightBrightnessInput.value = 80; // Set higher brightness during the night
}
}
// Function to display a congratulatory GIF
function displayCongratsGif() {
// Create a new image element for the GIF
const congratsGif = document.createElement('img');
congratsGif.src = 'celebration-emoji.gif';
congratsGif.id = 'congratsGif'; // Set the id of the GIF element
// Append the GIF to the body element
document.body.appendChild(congratsGif);
displayGifForDuration(congratsGif, 2000); // Display the GIF for 2 seconds
}
function displayThumbsGif() {
// Create a new image element for the GIF
const thumbsGif = document.createElement('img');
thumbsGif.src = 'thumbs-up.gif';
// Append the GIF to the body element
document.body.appendChild(thumbsGif);
displayGifForDuration(thumbsGif, 2000); // Display the GIF for 2 seconds
}
function displayGifForDuration(gifElement, duration) {
setTimeout(function() {
document.body.removeChild(gifElement);
}, duration);
}
// Function to listen for changes in temperature data from the database
function listenForTemperatureChanges() {
database.ref('temperature').on('value', function(snapshot) {
const temperature = snapshot.val();
updateTemperature(temperature);
});
}
// Initialize the temperature listener
listenForTemperatureChanges();
</script>
</body>
</html>