Test script
This commit is contained in:
parent
9f0a1e12c5
commit
056e7844ee
67
test.js
67
test.js
@ -4,26 +4,53 @@ const lpf2 = new LPF2();
|
|||||||
|
|
||||||
lpf2.scan();
|
lpf2.scan();
|
||||||
|
|
||||||
|
let moveHub = null,
|
||||||
|
moveHubUUID = "782a5fbbcef64c5cb31ab4791c191f5d";
|
||||||
|
wedoHub = null,
|
||||||
|
wedoHubUUID = "0ae95acf801e47f9bda4752392756eed";
|
||||||
|
|
||||||
lpf2.on("discover", (hub) => {
|
lpf2.on("discover", (hub) => {
|
||||||
hub.connect(() => {
|
hub.connect(() => {
|
||||||
console.log(`Connected to ${hub.uuid}`);
|
|
||||||
|
if (hub.uuid === moveHubUUID) {
|
||||||
|
moveHub = hub;
|
||||||
|
console.log("Connected to Move Hub");
|
||||||
|
|
||||||
|
moveHub.on("distance", (port, distance) => {
|
||||||
|
console.log(`Distance ${distance} received on port ${port}`);
|
||||||
|
if (distance < 80) {
|
||||||
|
moveHub.setMotorSpeed("D", 40);
|
||||||
|
} else {
|
||||||
|
moveHub.setMotorSpeed("D", 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (hub.uuid === wedoHubUUID) {
|
||||||
|
wedoHub = hub;
|
||||||
|
console.log("Connected to Smart Hub");
|
||||||
|
|
||||||
|
wedoHub.on("distance", (port, distance) => {
|
||||||
|
console.log(`Distance ${distance} received on port ${port}`);
|
||||||
|
if (distance < 80) {
|
||||||
|
wedoHub.setMotorSpeed("B", 40);
|
||||||
|
} else {
|
||||||
|
wedoHub.setMotorSpeed("B", 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
hub.on("distance", (port, distance) => {
|
|
||||||
console.log(`Distance ${distance} received on port ${port}`);
|
});
|
||||||
});
|
|
||||||
hub.on("color", (port, color) => {
|
|
||||||
console.log(`Color ${color} received on port ${port}`);
|
let color = 0;
|
||||||
});
|
|
||||||
hub.on("tilt", (port, x, y) => {
|
setInterval(() => {
|
||||||
console.log(`Tilt ${x}, ${y} received on port ${port}`);
|
|
||||||
});
|
color = color > 10 ? 1 : color + 1;
|
||||||
hub.on("rotate", (port, rotate) => {
|
if (moveHub) moveHub.setLEDColor(color);
|
||||||
console.log(`Rotate ${rotate} received on port ${port}`);
|
if (wedoHub) wedoHub.setLEDColor(color);
|
||||||
});
|
|
||||||
// setTimeout(() => {
|
}, 2000);
|
||||||
// hub.setMotorSpeed("C", 30);
|
|
||||||
// setTimeout(() => {
|
|
||||||
// hub.setMotorSpeed("C", 0);
|
|
||||||
// }, 3000);
|
|
||||||
// }, 3000);
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user