Fixed consts in examples
This commit is contained in:
parent
a4cff9bc74
commit
8f409acd5a
@ -30,26 +30,26 @@ poweredUP.on("discover", async (hub) => { // Wait to Batmobile and Remote
|
|||||||
remote.on("button", async (button, state) => {
|
remote.on("button", async (button, state) => {
|
||||||
if (batmobile) {
|
if (batmobile) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PoweredUP.Consts.ButtonStates.UP: // If up is pressed, move the wheels forward
|
case PoweredUP.Consts.ButtonState.UP: // If up is pressed, move the wheels forward
|
||||||
{
|
{
|
||||||
lastButton = state;
|
lastButton = state;
|
||||||
batmobile.setMotorSpeed(button === "LEFT" ? "B" : "A", button === "LEFT" ? -100 : 100);
|
batmobile.setMotorSpeed(button === "LEFT" ? "B" : "A", button === "LEFT" ? -100 : 100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.DOWN: // If down is pressed, move the wheels backwards
|
case PoweredUP.Consts.ButtonState.DOWN: // If down is pressed, move the wheels backwards
|
||||||
{
|
{
|
||||||
lastButton = state;
|
lastButton = state;
|
||||||
batmobile.setMotorSpeed(button === "LEFT" ? "B" : "A", button === "LEFT" ? 100 : -100);
|
batmobile.setMotorSpeed(button === "LEFT" ? "B" : "A", button === "LEFT" ? 100 : -100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.RELEASED: // Stop the wheels when the button is released
|
case PoweredUP.Consts.ButtonState.RELEASED: // Stop the wheels when the button is released
|
||||||
{
|
{
|
||||||
if (lastButton === PoweredUP.Consts.ButtonStates.UP || lastButton === PoweredUP.Consts.ButtonStates.DOWN) {
|
if (lastButton === PoweredUP.Consts.ButtonState.UP || lastButton === PoweredUP.Consts.ButtonState.DOWN) {
|
||||||
batmobile.setMotorSpeed(button === "LEFT" ? "B" : "A", 0);
|
batmobile.setMotorSpeed(button === "LEFT" ? "B" : "A", 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.STOP: // When left red button is pressed, do a retreat. When right red button is pressed, scan the area.
|
case PoweredUP.Consts.ButtonState.STOP: // When left red button is pressed, do a retreat. When right red button is pressed, scan the area.
|
||||||
{
|
{
|
||||||
lastButton = state;
|
lastButton = state;
|
||||||
if (button === "LEFT") {
|
if (button === "LEFT") {
|
||||||
@ -66,7 +66,7 @@ poweredUP.on("discover", async (hub) => { // Wait to Batmobile and Remote
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.PRESSED: // Do a wheelie when the green button is pressed
|
case PoweredUP.Consts.ButtonState.PRESSED: // Do a wheelie when the green button is pressed
|
||||||
{
|
{
|
||||||
lastButton = state;
|
lastButton = state;
|
||||||
if (button === "GREEN") {
|
if (button === "GREEN") {
|
||||||
|
@ -65,7 +65,7 @@ poweredUP.on("discover", async (hub) => {
|
|||||||
hub.on("button", (button, state) => {
|
hub.on("button", (button, state) => {
|
||||||
|
|
||||||
if (button === "GREEN") {
|
if (button === "GREEN") {
|
||||||
if (state === PoweredUP.Consts.ButtonStates.PRESSED) {
|
if (state === PoweredUP.Consts.ButtonState.PRESSED) {
|
||||||
hub._currentTrain++;
|
hub._currentTrain++;
|
||||||
if (hub._currentTrain >= trains.length) {
|
if (hub._currentTrain >= trains.length) {
|
||||||
hub._currentTrain = 0;
|
hub._currentTrain = 0;
|
||||||
@ -73,19 +73,19 @@ poweredUP.on("discover", async (hub) => {
|
|||||||
hub.setLEDColor(trains[hub._currentTrain].color);
|
hub.setLEDColor(trains[hub._currentTrain].color);
|
||||||
console.log(`Switched active train on remote ${hub.name} to ${trains[hub._currentTrain].name}`);
|
console.log(`Switched active train on remote ${hub.name} to ${trains[hub._currentTrain].name}`);
|
||||||
}
|
}
|
||||||
} else if ((button === "LEFT" || button === "RIGHT") && state !== PoweredUP.Consts.ButtonStates.RELEASED) {
|
} else if ((button === "LEFT" || button === "RIGHT") && state !== PoweredUP.Consts.ButtonState.RELEASED) {
|
||||||
trains[hub._currentTrain]._speed = trains[hub._currentTrain]._speed || 0;
|
trains[hub._currentTrain]._speed = trains[hub._currentTrain]._speed || 0;
|
||||||
if (state === PoweredUP.Consts.ButtonStates.UP) {
|
if (state === PoweredUP.Consts.ButtonState.UP) {
|
||||||
trains[hub._currentTrain]._speed += 10;
|
trains[hub._currentTrain]._speed += 10;
|
||||||
if (trains[hub._currentTrain]._speed > 100) {
|
if (trains[hub._currentTrain]._speed > 100) {
|
||||||
trains[hub._currentTrain]._speed = 100;
|
trains[hub._currentTrain]._speed = 100;
|
||||||
}
|
}
|
||||||
} else if (state === PoweredUP.Consts.ButtonStates.DOWN) {
|
} else if (state === PoweredUP.Consts.ButtonState.DOWN) {
|
||||||
trains[hub._currentTrain]._speed -= 10;
|
trains[hub._currentTrain]._speed -= 10;
|
||||||
if (trains[hub._currentTrain]._speed < -100) {
|
if (trains[hub._currentTrain]._speed < -100) {
|
||||||
trains[hub._currentTrain]._speed = -100;
|
trains[hub._currentTrain]._speed = -100;
|
||||||
}
|
}
|
||||||
} else if (state === PoweredUP.Consts.ButtonStates.STOP) {
|
} else if (state === PoweredUP.Consts.ButtonState.STOP) {
|
||||||
trains[hub._currentTrain]._speed = 0;
|
trains[hub._currentTrain]._speed = 0;
|
||||||
}
|
}
|
||||||
for (let trainHub in trains[hub._currentTrain].hubs) {
|
for (let trainHub in trains[hub._currentTrain].hubs) {
|
||||||
|
@ -28,29 +28,29 @@ poweredUP.on("discover", async (hub) => { // Wait to discover Vernie and Remote
|
|||||||
remote.on("button", async (button, state) => {
|
remote.on("button", async (button, state) => {
|
||||||
if (vernie) {
|
if (vernie) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PoweredUP.Consts.ButtonStates.UP: // If up is pressed, move the track forward
|
case PoweredUP.Consts.ButtonState.UP: // If up is pressed, move the track forward
|
||||||
{
|
{
|
||||||
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 50);
|
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 50);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.DOWN: // If down is pressed, move the track backwards
|
case PoweredUP.Consts.ButtonState.DOWN: // If down is pressed, move the track backwards
|
||||||
{
|
{
|
||||||
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", -50);
|
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", -50);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.RELEASED: // Stop the track when the button is released
|
case PoweredUP.Consts.ButtonState.RELEASED: // Stop the track when the button is released
|
||||||
{
|
{
|
||||||
if (button !== "GREEN") {
|
if (button !== "GREEN") {
|
||||||
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 0);
|
vernie.setMotorSpeed(button === "LEFT" ? "A" : "B", 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.STOP: // Move the head left or right when a red button is pressed
|
case PoweredUP.Consts.ButtonState.STOP: // Move the head left or right when a red button is pressed
|
||||||
{
|
{
|
||||||
await vernie.setMotorAngle("D", 35, button === "LEFT" ? -20 : 20);
|
await vernie.setMotorAngle("D", 35, button === "LEFT" ? -20 : 20);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PoweredUP.Consts.ButtonStates.PRESSED: // Fire when the green button is pressed
|
case PoweredUP.Consts.ButtonState.PRESSED: // Fire when the green button is pressed
|
||||||
{
|
{
|
||||||
if (button === "GREEN") {
|
if (button === "GREEN") {
|
||||||
await vernie.setMotorAngle("D", 80, 20);
|
await vernie.setMotorAngle("D", 80, 20);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user