... | @@ -88,6 +88,83 @@ You can check to make sure that you have the library by searching for the librar |
... | @@ -88,6 +88,83 @@ You can check to make sure that you have the library by searching for the librar |
|
### Step 7: Further Exploration
|
|
### Step 7: Further Exploration
|
|
* Can you think of a way to incorporate a reverse function for the microbot? What if you needed to push and hold a+b to make it move in a direction? How would you select between forward and reverse? Spend some time exploring with your Micro::Bit and see what kind of improvements you can make.
|
|
* Can you think of a way to incorporate a reverse function for the microbot? What if you needed to push and hold a+b to make it move in a direction? How would you select between forward and reverse? Spend some time exploring with your Micro::Bit and see what kind of improvements you can make.
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
Potential Javascript Edit, Add Reverse functionality, excerpt from controller.js(Click to Expand)
|
|
|
|
</summary>
|
|
|
|
<pre>
|
|
|
|
input.onButtonPressed(Button.AB, () => {
|
|
|
|
if (groupSet == 0) {
|
|
|
|
groupSet = 1
|
|
|
|
radio.setGroup(radioGroup)
|
|
|
|
basic.showIcon(IconNames.Happy)
|
|
|
|
} else {
|
|
|
|
radio.sendString("reverse") //change forward to reverse
|
|
|
|
basic.showLeds(` //change LED pattern to down arrow
|
|
|
|
. . # . .
|
|
|
|
. . # . .
|
|
|
|
# . # . #
|
|
|
|
. # # # .
|
|
|
|
. . # . .
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</pre>
|
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
Potential Javascript Edit, Add Reverse functionality, excerpt from robot.js(Click to Expand)
|
|
|
|
</summary>
|
|
|
|
<pre>
|
|
|
|
radio.onDataPacketReceived( ({ receivedString: remoteString }) => {
|
|
|
|
if (remoteString == "reverse") {
|
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Reverse, 100) //set motor to reverse
|
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, 100) //set motor to reverse
|
|
|
|
basic.showLeds(` //change LED to down arrow patters
|
|
|
|
. . # . .
|
|
|
|
. . # . .
|
|
|
|
# . # . #
|
|
|
|
. # # # .
|
|
|
|
. . # . .
|
|
|
|
`)
|
|
|
|
basic.pause(200)
|
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
|
|
} else if (remoteString == "left") {
|
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Reverse, 50)
|
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
|
|
|
|
basic.showLeds(`
|
|
|
|
. . # . .
|
|
|
|
. # . . .
|
|
|
|
# # # # #
|
|
|
|
. # . . .
|
|
|
|
. . # . .
|
|
|
|
`)
|
|
|
|
basic.pause(200)
|
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
|
|
} else if (remoteString == "right") {
|
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 50)
|
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, 50)
|
|
|
|
basic.showLeds(`
|
|
|
|
. . # . .
|
|
|
|
. . . # .
|
|
|
|
# # # # #
|
|
|
|
. . . # .
|
|
|
|
. . # . .
|
|
|
|
`)
|
|
|
|
basic.pause(200)
|
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
|
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</pre>
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
<details>
|
|
<details>
|
|
<summary>
|
|
<summary>
|
|
Potential Python Edit, Add Reverse functionality, controller.py(Click to Expand)
|
|
Potential Python Edit, Add Reverse functionality, controller.py(Click to Expand)
|
... | @@ -96,6 +173,7 @@ You can check to make sure that you have the library by searching for the librar |
... | @@ -96,6 +173,7 @@ You can check to make sure that you have the library by searching for the librar |
|
from microbit import *
|
|
from microbit import *
|
|
import radio
|
|
import radio
|
|
|
|
|
|
|
|
|
|
radio_group = 0 #number of radio frequency to use
|
|
radio_group = 0 #number of radio frequency to use
|
|
reverse = False #Changed forward var to reverse
|
|
reverse = False #Changed forward var to reverse
|
|
group_set = False #has the radio group been set?
|
|
group_set = False #has the radio group been set?
|
... | | ... | |