Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Created June 27, 2023 15:52
Show Gist options
  • Save AstraLuma/a96f8ebab8ec44f1262e310103caf6a5 to your computer and use it in GitHub Desktop.
Save AstraLuma/a96f8ebab8ec44f1262e310103caf6a5 to your computer and use it in GitHub Desktop.
Pixels dice quick vanilla page
<!doctype html>
<html>
<head><title>Pixels Quickie</title></head>
<body>
<script type=module>
import {
requestPixel
} from "https://unpkg.com/@systemic-games/pixels-web-connect?module";
// Ask user to select a Pixel
const pixel = await requestPixel();
// Connect to die
console.log("Connecting...");
await pixel.connect();
// Get last roll state
const rollState = pixel.rollState;
console.log(`=> roll state: ${rollState.state}, face up: ${rollState.face}`);
// Read RSSI (signal strength)
const rssi = await pixel.queryRssi();
console.log(`=> rssi: ${rssi}`);
// And battery level
console.log(`=> Battery: ${pixel.batteryLevel}%`);
// Make LEDs flash a color
await pixel.blink(Color.red);
// Add listener to get notified on rolls
pixel.addEventListener("roll", (face) => {
console.log(`=> rolled face: ${face}`);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment