Vernie remote example
This commit is contained in:
parent
73e7f89f6f
commit
7c8fef7e31
50
examples/vernie_remote.js
Normal file
50
examples/vernie_remote.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
const LPF2 = require("..");
|
||||||
|
|
||||||
|
const lpf2 = new LPF2.LPF2();
|
||||||
|
lpf2.scan(); // Start scanning for Vernie
|
||||||
|
|
||||||
|
console.log("Looking for Vernie (Please turn on the Hub now)...");
|
||||||
|
|
||||||
|
let vernie = null;
|
||||||
|
let remote = null;
|
||||||
|
|
||||||
|
lpf2.on("discover", async (hub) => { // Wait to discover Vernie
|
||||||
|
|
||||||
|
if (hub.type === LPF2.Consts.Hubs.BOOST_MOVE_HUB) {
|
||||||
|
vernie = hub;
|
||||||
|
await vernie.connect();
|
||||||
|
console.log("Connected to Vernie!");
|
||||||
|
|
||||||
|
|
||||||
|
} else if (hub.type === LPF2.Consts.Hubs.POWERED_UP_REMOTE) {
|
||||||
|
remote = hub;
|
||||||
|
|
||||||
|
remote.on("button", (button, state) => {
|
||||||
|
switch (state) {
|
||||||
|
case LPF2.Consts.ButtonStates.UP:
|
||||||
|
{
|
||||||
|
vernie && vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 50);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LPF2.Consts.ButtonStates.DOWN:
|
||||||
|
{
|
||||||
|
vernie && vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", -50);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LPF2.Consts.ButtonStates.RELEASED:
|
||||||
|
{
|
||||||
|
vernie && vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await remote.connect();
|
||||||
|
console.log("Connected to Powered Up Remote!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vernie && remote) {
|
||||||
|
console.log("You're now ready to go!");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user