Advertisement
iqhtyar2k

WebRemoteRcBot

Jan 27th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>Remote Control</title>
  7.   <style>
  8.     body {
  9.       font-family: Arial, sans-serif;
  10.       text-align: center;
  11.     }
  12.     .btn {
  13.       display: inline-block;
  14.       padding: 10px 20px;
  15.       margin: 10px;
  16.       font-size: 18px;
  17.       cursor: pointer;
  18.       background-color: #007bff;
  19.       color: #fff;
  20.       border: none;
  21.       border-radius: 5px;
  22.     }
  23.     .btn:hover {
  24.       background-color: #0056b3;
  25.     }
  26.     input[type="number"] {
  27.       width: 60px;
  28.       font-size: 16px;
  29.       padding: 5px;
  30.     }
  31.   </style>
  32. </head>
  33. <body>
  34.   <h1>Remote Control</h1>
  35.   <div>
  36.     <button class="btn" onclick="sendCommand('forward')">Forward</button>
  37.   </div>
  38.   <div>
  39.     <button class="btn" onclick="sendCommand('left')">Left</button>
  40.     <img src="chatbot.gif" alt="EspRCarBot" width="100">
  41.     <button class="btn" onclick="sendCommand('right')">Right</button>
  42.   </div>
  43. <div>
  44.     <button class="btn" onclick="sendCommand('backward')">Backward</button>
  45.   </div>
  46.   <div>
  47.     <input type="number" id="speed" value="100" min="0" max="255">
  48.     <button class="btn" onclick="SetSpeed()"> Speed</button>
  49.     <button class="btn" onclick="sendCommand('netral')">Netral</button>
  50.   </div>
  51.   <script>
  52.     var ipAddress = "192.168.4.1:80"; // Ubah sesuai dengan alamat IP ESP8266 dalam mode AP
  53.  
  54.     function sendCommand(command) {
  55.       fetch('http://' + ipAddress + '/' + command, { method: 'POST' })
  56.         .then(response => console.log('Command sent:', command))
  57.         .catch(error => console.error('Error sending command:', error));
  58.     }
  59.  
  60.     function setSpeed() {
  61.       var speed = document.getElementById('speed').value;
  62.       fetch('http://' + ipAddress + '/speed', { method: 'POST', body: 'speed=' + speed })
  63.         .then(response => console.log('Speed set to:', speed))
  64.         .catch(error => console.error('Error setting speed:', error));
  65.     }
  66.   </script>
  67. </body>
  68. <body>
  69.     <p>Mau tanya apa d^_^b:</p>
  70.  
  71.     <input id="input" type="text" placeholder="Type here">
  72.     <button onclick="askQuestion()">Ask</button>
  73.  
  74.     <p id="response"></p>
  75.  
  76. </script>
  77.  
  78.     <script>
  79.         // Load data from localStorage
  80.         var storedAnswers = JSON.parse(localStorage.getItem("chatbotAnswers")) || {};
  81.  
  82.         function saveToLocalStorage() {
  83.             localStorage.setItem("chatbotAnswers", JSON.stringify(storedAnswers));
  84.         }
  85.  
  86.         function askQuestion() {
  87.             // get the question from the user
  88.             var question = document.getElementById("input").value;
  89.  
  90.             // your extended AI logic goes here
  91.             if (storedAnswers.hasOwnProperty(question)) {
  92.                 document.getElementById("response").innerHTML = storedAnswers[question];
  93.             } else {
  94.                 var userAnswer = prompt("Maaf, aku enggak mengerti pertanyaan kamu. Aku harus jawab apa ya? :");
  95.                 storedAnswers[question] = "d^_^b  " + userAnswer;
  96.                 document.getElementById("response").innerHTML = storedAnswers[question];
  97.                 // Save updated data to localStorage
  98.                 saveToLocalStorage();
  99.             }
  100.         }
  101.     </script>
  102.  
  103. </body>
  104. </html>
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement