5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10



Micro:bit Smart Robot Tutorial 0-1-3.About methods of python programming

Posted by SuFiona on

Introduction of python programming methods

Programming online

1. You should use the USB cable to connect the micro:bit to the computer, at this point, the computer will have a micro:bit U disk. You need to open it, click micro:bit website, then entered the micro:bit website or you can enter the URL directly in your browser: http://microbit.org/. 

image.png 

2.After entering the official website, you can see the interface shown below.

image.png 3.You need to click “lets code”.

image.png

image.png 

4. Then you can enter the programming interface as shown below.

image.png

image.pngDownload:When you click “Download” button, a hex file will is saved on your compute.You need to make sure that the micro:bit development board is connected to the computer. You need to copy this hex file to the U disk in Micro:bit or send it to the U disk in Micro:bit. The code will run on micro:bit (or see an error message scrolling on the micro:bit dot matrix).

image.pngSave:When you click “Save”button. The code will be saved to your computer in "py" format.

image.pngLoad:Load the program file from the computer, it can be a "hex" file or a "py" file. Click the "Load" button, the gray area will appear, as shown in the following figure. You can drag the code file to the gray area to open Program file, or you can directly click on "Or pick a file" below to select the program file from the computer and open it.

image.png 

image.pngSnippets:Clicking on the "Snippets" button will bring up a program menu for the Python code snippet. For some common functions, there are some code snippets. You can choose the code snippet you need and fill it to the blanks of the code editor to realize some function

image.pngHelp:Clicking on the "Help" button will open a new tab in the browser that explains the use of the Python editor.

image.png+-:Clicking on the "+" button will enlarge font of code,Clicking on the "-" button will narrow font of code.

 5. For example: If we need to display the code of “Hello, World!” on the micro:bit dot matrix, you can write the code in the editing area, then connect the micro:bit board to your computer by micro USB cable, as shown in the following figure. You need to click “Download” to download the code to micro:bit.

image.png 

6.You can set the download path in the U disk of micro:bit, download it to the computer, and then copy it to the U disk in micro:bit. As shown in the following figure.

image.png 

7.After clicking the download, you can observe that the indicator light on the micro:bit board is flashing, indicating that the program is being downloaded.

image.png 

8.When the indicator light is on, indicating that the program is downloaded successfully. At this point, you can see that the micro:bit dot matrix is slowly moving to the left, "Hello, World!".

image.png   image.png

Programming offline

URL:https://codewith.mu/

1.You need to open browser, input this URL to download software. You need to click “Download now”, as shown in the following figure.

image.png 

2.Next, you will jump to the selection interface, and select your current computer system and click Download. There are three options to choose from, followed by Windows, OSX, and Linux. As shown in the following figure.

image.png 

3.You can run Mu after downloading.

image.png 

image.png

image.pngLoad:Load the "py" program file from the computer

image.pngSave:When you click “Save”button. The code will be saved to your computer in "py" format.

image.pngFlash:You need to make sure that the micro:bit development board is connected to the computer. When you click “Download” button, the code will run on micro:bit (or see an error message scrolling on the micro:bit dot matrix). 

image.pngZoom-in:Clicking on the "+" button will enlarge font of code

image.pngZoom-out:Clicking on the "-" button will narrow font of code.

image.pngTheme:Clicking "Theme" to switch between day and night themes.

image.pngCheck:After the code is written, click the "Check" button to Check for errors.

image.pngHelp:Clicking the "Help" button will pop up a page in the browser that will give you some help.

image.png 

Quit: Click the “Quit” button to close the Mu software. Before closing, Mu will ensure that you have saved your program files.

4.For example: If we need to display the code of “Hello, World!” on the micro:bit dot matrix, you can write the code in the editing area, then connect the micro:bit board to your computer by micro USB cable, as shown in the following figure. You need to click “Flash” to download the code to micro:bit. 

from microbit import *
display.scroll("Hello, World!")  

Note:

1 - The capital letter / lowercase letters must be distinguished!

2 - Correct spelling!

3 - Keywords such as # need a space between the content.

4 - The program ends with a blank program.

5 - The block body (such as the body of the while is marked by indentation), compared to the C language, Python completely eliminates the braces (along with the semicolon of the suffix), and uses the indentation structure to represent the relationship.

6 - Use the Tab key (tab) to indent.

image.png 

5.After the code is written, we can click the “Check ”button of the thumb icon to check our codes.

image.png 

6. After the check is completed, if the code no error. You need to make sure that the micro:bit development board is connected to the computer and you need to click “Flash” button.

image.png 

7.After clicking the Flash, you can observe that the indicator light on the micro:bit board is flashing, indicating that the program is being downloaded. As shown in the following figure.

image.png 

8.When the indicator light is on, indicating that the program is downloaded successfully. At the same time, the prompt will appear on Mu. You just need to click OK. As shown in the following figure.

image.png 

9.At this point, you can see that the micro:bit dot matrix is slowly moving to the left, "Hello, World!". As shown in the following figure.

image.png   image.png

0-1.Preparation before use

0 comments

Leave a comment

Please note, comments must be approved before they are published