... | ... | @@ -118,20 +118,20 @@ You can check to make sure that you have the library by searching for the librar |
|
|
|
|
|
5. Flash the robot hex file to one Micro::Bit and the controller hex file to the other. You should be able to choose a radio group on each and lock it in. From there, you should be able to drive your robot using the controller. To help you in the debugging process, we have provided a potential solution. The completed code for these solutions (as well as pictures of the completed code blocks) is included in the directory you downloaded during setup.
|
|
|
|
|
|
<details>
|
|
|
<summary>
|
|
|
<details>
|
|
|
<summary>
|
|
|
Potential JavaScript Robot Solution, robot.js (Click to Expand)
|
|
|
</summary>
|
|
|
<pre>
|
|
|
let radioGroup = 0
|
|
|
let groupSet = 0
|
|
|
input.onButtonPressed(Button.AB, () => {
|
|
|
</summary>
|
|
|
<pre>
|
|
|
let radioGroup = 0
|
|
|
let groupSet = 0
|
|
|
input.onButtonPressed(Button.AB, () => {
|
|
|
if (groupSet != 1) {
|
|
|
groupSet = 1
|
|
|
radio.setGroup(radioGroup)
|
|
|
}
|
|
|
})
|
|
|
radio.onDataPacketReceived( ({ receivedString: remoteString }) => {
|
|
|
})
|
|
|
radio.onDataPacketReceived( ({ receivedString: remoteString }) => {
|
|
|
if (remoteString == "forward") {
|
|
|
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 100)
|
|
|
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 100)
|
... | ... | @@ -174,36 +174,36 @@ You can check to make sure that you have the library by searching for the librar |
|
|
} else {
|
|
|
|
|
|
}
|
|
|
})
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
})
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
if (groupSet != 1 && radioGroup > 0) {
|
|
|
radioGroup = radioGroup - 1
|
|
|
}
|
|
|
})
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
})
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
if (groupSet != 1 && radioGroup < 255) {
|
|
|
radioGroup = radioGroup + 1
|
|
|
}
|
|
|
})
|
|
|
while (groupSet != 1) {
|
|
|
})
|
|
|
while (groupSet != 1) {
|
|
|
basic.showNumber(radioGroup)
|
|
|
}
|
|
|
basic.showIcon(IconNames.Happy)
|
|
|
basic.pause(100)
|
|
|
basic.showNumber(radioGroup)
|
|
|
motobit.enable(MotorPower.On)
|
|
|
}
|
|
|
basic.showIcon(IconNames.Happy)
|
|
|
basic.pause(100)
|
|
|
basic.showNumber(radioGroup)
|
|
|
motobit.enable(MotorPower.On)
|
|
|
|
|
|
</pre>
|
|
|
</details>
|
|
|
</pre>
|
|
|
</details>
|
|
|
|
|
|
<details>
|
|
|
<summary>
|
|
|
<details>
|
|
|
<summary>
|
|
|
Potential JavaScript Controller Solution, controller.js (Click to Expand)
|
|
|
</summary>
|
|
|
<pre>
|
|
|
let groupSet = 0
|
|
|
let radioGroup = 0
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
</summary>
|
|
|
<pre>
|
|
|
let groupSet = 0
|
|
|
let radioGroup = 0
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
if (groupSet == 0 && radioGroup > 0) {
|
|
|
radioGroup = radioGroup - 1
|
|
|
} else {
|
... | ... | @@ -216,8 +216,8 @@ You can check to make sure that you have the library by searching for the librar |
|
|
. . # . .
|
|
|
`)
|
|
|
}
|
|
|
})
|
|
|
input.onButtonPressed(Button.AB, () => {
|
|
|
})
|
|
|
input.onButtonPressed(Button.AB, () => {
|
|
|
if (groupSet == 0) {
|
|
|
groupSet = 1
|
|
|
radio.setGroup(radioGroup)
|
... | ... | @@ -232,8 +232,8 @@ You can check to make sure that you have the library by searching for the librar |
|
|
. . # . .
|
|
|
`)
|
|
|
}
|
|
|
})
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
})
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
if (groupSet == 0 && radioGroup < 255) {
|
|
|
radioGroup = radioGroup + 1
|
|
|
} else {
|
... | ... | @@ -246,33 +246,33 @@ You can check to make sure that you have the library by searching for the librar |
|
|
. . # . .
|
|
|
`)
|
|
|
}
|
|
|
})
|
|
|
radioGroup = 0
|
|
|
while (groupSet != 1) {
|
|
|
})
|
|
|
radioGroup = 0
|
|
|
while (groupSet != 1) {
|
|
|
basic.showNumber(radioGroup)
|
|
|
}
|
|
|
basic.showIcon(IconNames.Happy)
|
|
|
basic.pause(100)
|
|
|
basic.showNumber(radioGroup)
|
|
|
}
|
|
|
basic.showIcon(IconNames.Happy)
|
|
|
basic.pause(100)
|
|
|
basic.showNumber(radioGroup)
|
|
|
|
|
|
</pre>
|
|
|
</details>
|
|
|
</pre>
|
|
|
</details>
|
|
|
|
|
|
<details>
|
|
|
<summary>
|
|
|
<details>
|
|
|
<summary>
|
|
|
Potential Python Robot Solution, excerpt from robot.py (Click to Expand)
|
|
|
</summary>
|
|
|
<pre>
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
</summary>
|
|
|
<pre>
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
|
|
|
############################
|
|
|
#NEW CODE
|
|
|
############################
|
|
|
#NEW CODE
|
|
|
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
|
|
|
class MotoBit:
|
|
|
class MotoBit:
|
|
|
moto_l = 0x21
|
|
|
moto_r = 0x20
|
|
|
moto_on = 0x70
|
... | ... | @@ -305,20 +305,20 @@ You can check to make sure that you have the library by searching for the librar |
|
|
|
|
|
|
|
|
|
|
|
radio_group = 0 #number of radio frequency to use
|
|
|
group_set = False #has the radio group been set?
|
|
|
motobit = MotoBit()
|
|
|
motobit.enable(True) # Enable motor driver
|
|
|
radio.on()
|
|
|
radio.config(power=7)
|
|
|
radio_group = 0 #number of radio frequency to use
|
|
|
group_set = False #has the radio group been set?
|
|
|
motobit = MotoBit()
|
|
|
motobit.enable(True) # Enable motor driver
|
|
|
radio.on()
|
|
|
radio.config(power=7)
|
|
|
|
|
|
stop_sign = Image( "09990:"
|
|
|
stop_sign = Image( "09990:"
|
|
|
"90099:"
|
|
|
"90909:"
|
|
|
"99009:"
|
|
|
"09990")
|
|
|
|
|
|
while True:# do forever
|
|
|
while True:# do forever
|
|
|
if not group_set:
|
|
|
display.show(str(radio_group))
|
|
|
if button_a.is_pressed() and button_b.is_pressed():
|
... | ... | @@ -355,30 +355,30 @@ You can check to make sure that you have the library by searching for the librar |
|
|
motobit.drive(0,0)
|
|
|
sleep(100)
|
|
|
|
|
|
</pre>
|
|
|
</details>
|
|
|
</pre>
|
|
|
</details>
|
|
|
|
|
|
<details>
|
|
|
<summary>
|
|
|
<details>
|
|
|
<summary>
|
|
|
Potential Python Controller Solution, controller.py (Click to Expand)
|
|
|
</summary>
|
|
|
<pre>
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
|
|
|
radio_group = 0 #number of radio frequency to use
|
|
|
forward = False
|
|
|
group_set = False #has the radio group been set?
|
|
|
radio.on()
|
|
|
radio.config(power=7)
|
|
|
|
|
|
stop_sign = Image( "09990:"
|
|
|
</summary>
|
|
|
<pre>
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
|
|
|
radio_group = 0 #number of radio frequency to use
|
|
|
forward = False
|
|
|
group_set = False #has the radio group been set?
|
|
|
radio.on()
|
|
|
radio.config(power=7)
|
|
|
|
|
|
stop_sign = Image( "09990:"
|
|
|
"90099:"
|
|
|
"90909:"
|
|
|
"99009:"
|
|
|
"09990")
|
|
|
|
|
|
while True:# do forever
|
|
|
while True:# do forever
|
|
|
if group_set is False:
|
|
|
display.show(str(radio_group))
|
|
|
|
... | ... | @@ -413,10 +413,10 @@ You can check to make sure that you have the library by searching for the librar |
|
|
display.show(Image.ARROW_E)
|
|
|
sleep(200)
|
|
|
|
|
|
</pre>
|
|
|
</details>
|
|
|
</pre>
|
|
|
</details>
|
|
|
|
|
|
<br></br>
|
|
|
<br></br>
|
|
|
|
|
|
6. Test your code.
|
|
|
* Your robot should:
|
... | ... | |