-
Notifications
You must be signed in to change notification settings - Fork 0
/
EspRCarBot.html
95 lines (86 loc) · 2.73 KB
/
EspRCarBot.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Remote Control</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
.btn {
display: inline-block;
padding: 10px 20px;
margin: 10px;
font-size: 18px;
cursor: pointer;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
}
.btn:hover {
background-color: #0056b3;
}
input[type="number"] {
width: 60px;
font-size: 16px;
padding: 5px;
}
</style>
</head>
<body>
<h1>Remote Control</h1>
<div>
<button class="btn" onclick="sendCommand('forward')">Forward</button>
</div>
<div>
<button class="btn" onclick="sendCommand('left')">Left</button>
<img src="chatbot.gif" alt="EspRCarBot" width="100">
<button class="btn" onclick="sendCommand('right')">Right</button>
</div>
<div>
<button class="btn" onclick="sendCommand('backward')">Backward</button>
</div>
<div>
<button class="btn" onclick="sendCommand('netral')">Netral</button>
</div>
<script>
var ipAddress = "192.168.4.1:80"; // Ubah sesuai dengan alamat IP ESP8266 dalam mode AP
function sendCommand(command) {
fetch('http://' + ipAddress + '/' + command, { method: 'POST' })
.then(response => console.log('Command sent:', command))
.catch(error => console.error('Error sending command:', error));
}
</script>
</body>
<body>
<p>Mau tanya apa d^_^b:</p>
<input id="input" type="text" placeholder="Type here">
<button onclick="askQuestion()">Ask</button>
<p id="response"></p>
</script>
<script>
// Load data from localStorage
var storedAnswers = JSON.parse(localStorage.getItem("chatbotAnswers")) || {};
function saveToLocalStorage() {
localStorage.setItem("chatbotAnswers", JSON.stringify(storedAnswers));
}
function askQuestion() {
// get the question from the user
var question = document.getElementById("input").value;
// your extended AI logic goes here
if (storedAnswers.hasOwnProperty(question)) {
document.getElementById("response").innerHTML = storedAnswers[question];
} else {
var userAnswer = prompt("Maaf, aku enggak mengerti pertanyaan kamu. Aku harus jawab apa ya? :");
storedAnswers[question] = "d^_^b " + userAnswer;
document.getElementById("response").innerHTML = storedAnswers[question];
// Save updated data to localStorage
saveToLocalStorage();
}
}
</script>
</body>
</html>