node-poweredup/test.html

52 lines
950 B
HTML

<!DOCTYPE html>
<html>
<head>
<title>node-poweredup Web Bluetooth Test</title>
<script src="./dist/browser/poweredup.js"></script>
<script>
const poweredUP = new PoweredUP.PoweredUP();
console.log("Looking for Hubs...");
poweredUP.on("discover", async (hub) => { // Wait to discover hubs
await hub.connect(); // Connect to hub
console.log(`Connected to ${hub.name}!`);
hub.on("disconnect", () => {
console.log("Hub disconnected");
})
});
const scan = async function () {
alert("ok");
poweredUP.scan(); // Start scanning for hubs
}
let color = 1;
setInterval(() => {
const hubs = poweredUP.getConnectedHubs(); // Get an array of all connected hubs
hubs.forEach((hub) => {
hub.setLEDColor(color); // Set the color
})
color++;
if (color > 10) {
color = 1;
}
}, 2000);
</script>
</head>
<body>
<div>
<button onclick="scan()" on>Scan</button>
</div>
</body>
</html>