Better comments
This commit is contained in:
parent
9cd657af81
commit
c61d3ec0d6
@ -15,9 +15,9 @@ lpf2.on("discover", async (hub) => { // Wait to discover hubs
|
||||
let color = 0;
|
||||
setInterval(() => {
|
||||
|
||||
const hubs = lpf2.getConnectedDevices();
|
||||
const hubs = lpf2.getConnectedDevices(); // Get an array of all connected hubs
|
||||
hubs.forEach((hub) => {
|
||||
hub.setLEDColor(color);
|
||||
hub.setLEDColor(color); // Set the color
|
||||
})
|
||||
color++;
|
||||
if (color > 10) {
|
||||
|
@ -10,15 +10,18 @@ lpf2.on("discover", async (hub) => { // Wait to discover hubs
|
||||
await hub.connect(); // Connect to hub
|
||||
console.log("Connected to Hub!");
|
||||
|
||||
await hub.wait(2000); // Wait two seconds before starting the train
|
||||
hub.setMotorSpeed("A", 40);
|
||||
|
||||
hub.on("color", (port, color) => {
|
||||
|
||||
if (color === LPF2.Consts.Colors.YELLOW) {
|
||||
if (color === LPF2.Consts.Colors.YELLOW) { // If yellow is seen, stop the train, wait two seconds, and reverse direction
|
||||
|
||||
hub.setMotorSpeed("A", 0);
|
||||
await hub.wait(2000);
|
||||
hub.setMotorSpeed("A", -40);
|
||||
|
||||
} else if (color === LPF2.Consts.Colors.RED) {
|
||||
} else if (color === LPF2.Consts.Colors.RED) { // If red is seen, stop the train, wait two seconds, and reverse direction
|
||||
|
||||
hub.setMotorSpeed("A", 0);
|
||||
await hub.wait(2000);
|
||||
@ -28,7 +31,4 @@ lpf2.on("discover", async (hub) => { // Wait to discover hubs
|
||||
|
||||
});
|
||||
|
||||
await hub.wait(2000);
|
||||
hub.setMotorSpeed("A", 40);
|
||||
|
||||
});
|
@ -22,29 +22,29 @@ lpf2.on("discover", async (hub) => { // Wait to discover Vernie and Remote
|
||||
remote.on("button", async (button, state) => {
|
||||
if (vernie) {
|
||||
switch (state) {
|
||||
case LPF2.Consts.ButtonStates.UP:
|
||||
case LPF2.Consts.ButtonStates.UP: // If up is pressed, move the track forward
|
||||
{
|
||||
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 50);
|
||||
break;
|
||||
}
|
||||
case LPF2.Consts.ButtonStates.DOWN:
|
||||
case LPF2.Consts.ButtonStates.DOWN: // If down is pressed, move the track backwards
|
||||
{
|
||||
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", -50);
|
||||
break;
|
||||
}
|
||||
case LPF2.Consts.ButtonStates.RELEASED:
|
||||
case LPF2.Consts.ButtonStates.RELEASED: // Stop the track when the button is released
|
||||
{
|
||||
if (button !== "GREEN") {
|
||||
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LPF2.Consts.ButtonStates.STOP:
|
||||
case LPF2.Consts.ButtonStates.STOP: // Move the head left or right when a red button is pressed
|
||||
{
|
||||
await vernie.setMotorAngle("D", 35, button === "LEFT" ? -20 : 20);
|
||||
break;
|
||||
}
|
||||
case LPF2.Consts.ButtonStates.PRESSED:
|
||||
case LPF2.Consts.ButtonStates.PRESSED: // Fire when the green button is pressed
|
||||
{
|
||||
if (button === "GREEN") {
|
||||
await vernie.setMotorAngle("D", 80, 20);
|
||||
@ -61,6 +61,8 @@ lpf2.on("discover", async (hub) => { // Wait to discover Vernie and Remote
|
||||
}
|
||||
|
||||
if (vernie && remote) {
|
||||
vernie.setLEDColor(LPF2.Consts.Colors.GREEN);
|
||||
remote.setLEDColor(LPF2.Consts.Colors.GREEN);
|
||||
console.log("You're now ready to go!");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user