How-to
Read the state of a device
Example: read the first device and its values.
const devices = deviceManager.getAllDevices();
if (devices.size > 0) {
const first = devices.values().next().value;
const data = first.getSensorData();
// data.ax, data.ay, data.az, data.dNW, data.dNE, data.dSW, data.dSE
}
Retrieve a known device by id (hex string):
Add a new Scene
- Create a new file under
socket-demo/scenes/, e.g.MyScene.js:
class MyScene extends Scene {
setup() {}
draw() {
background(30);
const count = this.deviceManager.getDeviceCount();
text(`Devices: ${count}`, 10, 20);
}
}
- Include it in
socket-demo/index.htmlbeforesketch.js:
- Register it in
socket-demo/sketch.js:
- Switch to it from code or console: