Skip to content

Commit c0009f8

Browse files
author
Nathan Kellenicki
committed
Updated vernie sample, added braking style
1 parent e34eea9 commit c0009f8

53 files changed

Lines changed: 19883 additions & 21677 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,22 @@ const poweredUP = new PoweredUP.PoweredUP();
6969
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
7070
console.log(`Discovered ${hub.name}!`);
7171
await hub.connect(); // Connect to the Hub
72+
const motorA = hub.waitForDeviceAtPort("A"); // Make sure a motor is plugged into port A
73+
const motorB = hub.waitForDeviceAtPort("B"); // Make sure a motor is plugged into port B
7274
console.log("Connected");
73-
await hub.sleep(3000); // Sleep for 3 seconds before starting
7475

7576
while (true) { // Repeat indefinitely
7677
console.log("Running motor B at speed 75");
77-
hub.setMotorSpeed("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
78+
motorB.setPower("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
7879
console.log("Running motor A at speed 100 for 2 seconds");
79-
await hub.setMotorSpeed("A", 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
80+
motorA.setPower("A", 100); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
81+
await hub.sleep(2000);
82+
motorA.setPower("A", 0);
8083
await hub.sleep(1000); // Do nothing for 1 second
81-
console.log("Running motor A at speed -50 for 1 seconds");
82-
await hub.setMotorSpeed("A", -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
84+
console.log("Running motor A at speed -50 for 1 second");
85+
motorA.setPower("A", -50); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
86+
hub.sleep(1000);
87+
motorA.setPower("A", 0);
8388
await hub.sleep(1000); // Do nothing for 1 second
8489
}
8590
});

0 commit comments

Comments
 (0)