Better Vernie example

This commit is contained in:
Nathan Kunicki 2018-06-22 15:46:39 +01:00
parent b1a84ebcd7
commit 138cca1b34

View File

@ -5,25 +5,25 @@ lpf2.scan(); // Start scanning for Vernie
console.log("Looking for Vernie (Please turn the Hub on now)..."); console.log("Looking for Vernie (Please turn the Hub on now)...");
lpf2.on("discover", async (hub) => { // Wait to discover Vernie lpf2.on("discover", async (vernie) => { // Wait to discover Vernie
lpf2.stop(); // Stop scanning for Vernie (We've already found one!) lpf2.stop(); // Stop scanning for Vernie (We've already found him!)
await hub.connect(); // Connect to Vernie await vernie.connect(); // Connect to Vernie
console.log("Connected to Vernie!"); console.log("Connected to Vernie!");
await hub.wait(3000); // Wait for 2 seconds before starting await vernie.wait(3000); // Wait for 2 seconds before starting
console.log("We're going on an adventure!"); console.log("We're going on an adventure!");
await hub.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds await vernie.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds
await hub.setMotorAngle("B", 360, 50); // Turn right await vernie.setMotorAngle("B", 360, 50); // Turn right
await hub.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds await vernie.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds
await hub.wait(1000); // Wait for 1 second await vernie.wait(1000); // Wait for 1 second
console.log("Better go home now..."); console.log("Better go home now...");
await hub.setMotorAngle("A", 720, 50); // Turn around await vernie.setMotorAngle("A", 720, 50); // Turn around
await hub.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds await vernie.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds
await hub.setMotorAngle("A", 360, 50); // Turn left await vernie.setMotorAngle("A", 360, 50); // Turn left
await hub.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds await vernie.setMotorSpeed("AB", 50, 2000); // Move forward for 2 seconds
await hub.setMotorAngle("A", 720, 50); // Turn around - Vernie should now be back in his original position! await vernie.setMotorAngle("A", 720, 50); // Turn around - Vernie should now be back in his original position!
}); });