... | ... | @@ -65,25 +65,62 @@ In the packages pop-up, search for "Motobit". Select the moto-bit library in the |
|
|
You can check to make sure that you have the library by searching for the library in your libraries toolbar.
|
|
|
|
|
|
![microbot_lib4](/uploads/50880517646fef4065f781d017771d02/microbot_lib4.PNG)
|
|
|
|
|
|
### Step 6: Programming!
|
|
|
1. Partner up
|
|
|
2. Open the robot base code by:
|
|
|
1.
|
|
|
3. Complete the robot code. Add:
|
|
|
1.
|
|
|
#. Set the radio group to your assigned group
|
|
|
4. Generate your robot .hex file
|
|
|
5. Open the the controller base code
|
|
|
6. Complete the controller robot code. Add:
|
|
|
1.
|
|
|
#. Set the radio group to your assigned group
|
|
|
7. Generate your controller .hex file
|
|
|
1. Partner up
|
|
|
2. Open the robot base code by:
|
|
|
1. Go to the files you downloaded from above
|
|
|
2. Double-click on the JavaScript or Python folder
|
|
|
3. Right-click on robot_base (JavaScript) or robot_base (Python)
|
|
|
4. Select "Open with Visual Code", "Open with Notepad++", or "Open with Notepad"
|
|
|
5. Highlight all of the text and copy it (right-click and copy or ctrl+c)
|
|
|
6. If you are using JavaScript/Blocks, in the editor, select the JavaScript button in the center-top of the page. If you are using Python, simply go to your editor.
|
|
|
7. Delete all of the existing code in the editor
|
|
|
8. Paste your code into the editor
|
|
|
9. If you are using Blocks, to get back to blocks, you can select the Blocks button in the center-top of the page.
|
|
|
3. Complete the robot code. You will add channel choosing functionality and give the motobit commands after receiving a radio transmission from the controller:
|
|
|
1. When button a and b are pressed, set the radio group
|
|
|
2. When button a is pressed, if the radio group has not been set, decrement the radio group by 1
|
|
|
3. When button b is pressed, if the radio group has not been set, increment the radio group by 1
|
|
|
4. When the command "forward" is received over the radio, drive the mototbit Forward
|
|
|
5. When the command "stop" is received over the radio, stop the motobit
|
|
|
6. When the command "left" is received over the radio, drive the mototbit left
|
|
|
7. When the command "right" is received over the radio, drive the mototbit right
|
|
|
4. Generate your robot .hex file. From your editor, click on the "Download" button in the bottom right hand corner. This will download your .hex file. You can find it in the Downloads folder on your computer.
|
|
|
|
|
|
![download](/uploads/c3c3a26fb266867fc4cbe74a08ab952e/download.PNG)
|
|
|
|
|
|
If you are using Mu (Python editor), you simply need to press the "flash" button. In other words, if you are working with Python, you don't have to generate a .hex file, you just need to press the "flash" button.
|
|
|
|
|
|
![flash_py](/uploads/f88092bbd58733b96896c29481a875b1/flash_py.PNG)
|
|
|
|
|
|
5. Open the controller base code by:
|
|
|
1. Go to the files you downloaded from above
|
|
|
2. Double-click on the JavaScript or Python folder. Stick with the same language as you chose for the robot_base
|
|
|
3. Right-click on controller_base (JavaScript) or controller_base (Python)
|
|
|
4. Select "Open with Visual Code", "Open with Notepad++", or "Open with Notepad"
|
|
|
5. Highlight all of the text and copy it (right-click and copy or ctrl+c)
|
|
|
6. If you are using JavaScript/Blocks, in the editor, select the JavaScript button in the center-top of the page. If you are using Python, simply go to your editor.
|
|
|
7. Delete all of the existing code in the editor
|
|
|
8. Paste your code into the editor
|
|
|
9. If you are using Blocks, to get back to blocks, you can select the Blocks button in the center-top of the page.
|
|
|
6. Complete the controller base code. You will add channel choosing functionality and send radio commands depending on the buttons pressed:
|
|
|
1. When button a and b are pressed, if the radio channel has not already been set, set it. if the radio channel has already been set, send a "forward" command over the radio
|
|
|
2. When button a is pressed, if the radio group has not been set, decrement the radio group by 1. if the radio group has been set, send a "left" command over the radio
|
|
|
3. When button b is pressed, if the radio group has not been set, increment the radio group by 1. if the radio group has been set, send a "right" command over the radio
|
|
|
7. Generate your controller .hex file. From your editor, click on the "Download" button in the bottom right hand corner. This will download your .hex file. You can find it in the Downloads folder on your computer.
|
|
|
|
|
|
![download](/uploads/c3c3a26fb266867fc4cbe74a08ab952e/download.PNG)
|
|
|
|
|
|
If you are using Mu (Python editor), you simply need to press the "flash" button. In other words, if you are working with Python, you don't have to generate a .hex file, you just need to press the "flash" button.
|
|
|
|
|
|
![flash_py](/uploads/f88092bbd58733b96896c29481a875b1/flash_py.PNG)
|
|
|
|
|
|
5. Flash the robot hex file to one Micro::Bit and the controller hex file to the other.
|
|
|
1.
|
|
|
6. Test your code. Your robot should:
|
|
|
1.
|
|
|
7. Now try to intercept other robots
|
|
|
7. Now try to intercept other robots
|
|
|
|
|
|
|
|
|
### 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.
|
... | ... | |