... | @@ -123,75 +123,75 @@ You can check to make sure that you have the library by searching for the librar |
... | @@ -123,75 +123,75 @@ You can check to make sure that you have the library by searching for the librar |
|
Potential JavaScript Solution, robot.js (Click to Expand)
|
|
Potential JavaScript Solution, robot.js (Click to Expand)
|
|
</summary>
|
|
</summary>
|
|
<pre>
|
|
<pre>
|
|
let radioGroup = 0
|
|
let radioGroup = 0
|
|
let groupSet = 0
|
|
let groupSet = 0
|
|
input.onButtonPressed(Button.AB, () => {
|
|
input.onButtonPressed(Button.AB, () => {
|
|
if (groupSet != 1) {
|
|
if (groupSet != 1) {
|
|
groupSet = 1
|
|
groupSet = 1
|
|
radio.setGroup(radioGroup)
|
|
radio.setGroup(radioGroup)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
radio.onDataPacketReceived( ({ receivedString: remoteString }) => {
|
|
radio.onDataPacketReceived( ({ receivedString: remoteString }) => {
|
|
if (remoteString == "forward") {
|
|
if (remoteString == "forward") {
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 100)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 100)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 100)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 100)
|
|
basic.showLeds(`
|
|
basic.showLeds(`
|
|
. . # . .
|
|
. . # . .
|
|
. # # # .
|
|
. # # # .
|
|
# . # . #
|
|
# . # . #
|
|
. . # . .
|
|
. . # . .
|
|
. . # . .
|
|
. . # . .
|
|
`)
|
|
`)
|
|
basic.pause(200)
|
|
basic.pause(200)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
} else if (remoteString == "left") {
|
|
} else if (remoteString == "left") {
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Reverse, 50)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Reverse, 50)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
|
|
basic.showLeds(`
|
|
basic.showLeds(`
|
|
. . # . .
|
|
. . # . .
|
|
. # . . .
|
|
. # . . .
|
|
# # # # #
|
|
# # # # #
|
|
. # . . .
|
|
. # . . .
|
|
. . # . .
|
|
. . # . .
|
|
`)
|
|
`)
|
|
basic.pause(200)
|
|
basic.pause(200)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
} else if (remoteString == "right") {
|
|
} else if (remoteString == "right") {
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 50)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 50)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, 50)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, 50)
|
|
basic.showLeds(`
|
|
basic.showLeds(`
|
|
. . # . .
|
|
. . # . .
|
|
. . . # .
|
|
. . . # .
|
|
# # # # #
|
|
# # # # #
|
|
. . . # .
|
|
. . . # .
|
|
. . # . .
|
|
. . # . .
|
|
`)
|
|
`)
|
|
basic.pause(200)
|
|
basic.pause(200)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
} else {
|
|
} else {
|
|
|
|
|
|
}
|
|
}
|
|
})
|
|
})
|
|
input.onButtonPressed(Button.A, () => {
|
|
input.onButtonPressed(Button.A, () => {
|
|
if (groupSet != 1 && radioGroup > 0) {
|
|
if (groupSet != 1 && radioGroup > 0) {
|
|
radioGroup = radioGroup - 1
|
|
radioGroup = radioGroup - 1
|
|
}
|
|
}
|
|
})
|
|
})
|
|
input.onButtonPressed(Button.B, () => {
|
|
input.onButtonPressed(Button.B, () => {
|
|
if (groupSet != 1 && radioGroup < 255) {
|
|
if (groupSet != 1 && radioGroup < 255) {
|
|
radioGroup = radioGroup + 1
|
|
radioGroup = radioGroup + 1
|
|
}
|
|
}
|
|
})
|
|
})
|
|
while (groupSet != 1) {
|
|
while (groupSet != 1) {
|
|
basic.showNumber(radioGroup)
|
|
basic.showNumber(radioGroup)
|
|
}
|
|
}
|
|
basic.showIcon(IconNames.Happy)
|
|
basic.showIcon(IconNames.Happy)
|
|
basic.pause(100)
|
|
basic.pause(100)
|
|
basic.showNumber(radioGroup)
|
|
basic.showNumber(radioGroup)
|
|
motobit.enable(MotorPower.On)
|
|
motobit.enable(MotorPower.On)
|
|
|
|
|
|
</pre>
|
|
</pre>
|
|
</details>
|
|
</details>
|
... | @@ -202,6 +202,7 @@ You can check to make sure that you have the library by searching for the librar |
... | @@ -202,6 +202,7 @@ You can check to make sure that you have the library by searching for the librar |
|
Potential JavaScript Solution, controller.js (Click to Expand)
|
|
Potential JavaScript Solution, controller.js (Click to Expand)
|
|
</summary>
|
|
</summary>
|
|
<pre>
|
|
<pre>
|
|
|
|
|
|
let groupSet = 0
|
|
let groupSet = 0
|
|
let radioGroup = 0
|
|
let radioGroup = 0
|
|
input.onButtonPressed(Button.A, () => {
|
|
input.onButtonPressed(Button.A, () => {
|
... | @@ -255,6 +256,7 @@ You can check to make sure that you have the library by searching for the librar |
... | @@ -255,6 +256,7 @@ You can check to make sure that you have the library by searching for the librar |
|
basic.showIcon(IconNames.Happy)
|
|
basic.showIcon(IconNames.Happy)
|
|
basic.pause(100)
|
|
basic.pause(100)
|
|
basic.showNumber(radioGroup)
|
|
basic.showNumber(radioGroup)
|
|
|
|
|
|
</pre>
|
|
</pre>
|
|
</details>
|
|
</details>
|
|
<br></br>
|
|
<br></br>
|
... | | ... | |