mini-test / static /main.js
cduss's picture
update
cf34346
raw
history blame contribute delete
951 Bytes
const robotIp = "http://127.0.0.1:5001"
window.onload = () => {
const container = document.getElementById("sliders");
for (let i = 0; i < 6; i++) {
const label = document.createElement("label");
label.innerText = `Motor ${i}`;
const input = document.createElement("input");
input.type = "range";
input.min = 0;
input.max = 100;
input.value = 0;
input.oninput = () => {
fetch(`${robotIp}/motor_control`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ [`motor_${i}`]: parseFloat(input.value) }),
}).catch(err => console.error("Send error:", err));
};
container.appendChild(label);
container.appendChild(document.createElement("br"));
container.appendChild(input);
container.appendChild(document.createElement("br"));
}
};