Welcome to Building:bit Superkit repository
3.Transportation
Transportation
Transportation1. Learning Objectives2. Building Blocks3. Motor Wiring4. Code analysis5. Write and download the program6. Experimental phenomenon
1. Learning Objectives
In this course, we mainly learn how to implement it through Python programming. After pressing the micro:bit A button, the shovel is lifted -> forward 2 seconds -> unload the goods -> shovel is placed flat -> back 2 seconds.
2. Building Blocks
For the building block steps, please refer to the installation drawings of [Assembly course]-[Proficient carrier] in the materials or the building block installation album.
3. Motor Wiring
The motor wiring on the left side of the car is inserted into the M1 interface of the Super:bit expansion board, and the black wire is close to the battery side;
The motor wiring on the right side of the car is inserted into the M3 interface of the Super:bit expansion board, and the black wire is close to the battery side;
The building block servo wiring is inserted into the S1 interface of the Super:bit expansion board, and the orange servo wiring is inserted into the yellow pin of S1.
As shown below:

! Notes:
When taking a course related to the building block servo for the first time, we need to remove the gear on the servo first and upload the program of this course to the micro:bit; then turn on the power switch of the Super:bit expansion board and wait for the building block servo to turn to the initial position; then, we can turn off the power, adjust the angle of the shovel of the trolley to be parallel to the ground, and then install the servo gear. (If you have used the program related to the transport master and the servo before, you can skip this step)

4. Code analysis
For the program of this course, please see the Transportation.py file.
from microbit import *import superbitimport microbitFirst, import the libraries needed for this lesson from microbit: the superbit library is compatible with the superbit expansion board;
xxxxxxxxxxdisplay.show(Image.HAPPY)superbit.servo270(superbit.S1, 120)display.show(Image.HAPPY): Display a smiley face pattern on the microbit dot matrix;
superbit.servo270(superbit.S1, 120): Initialize the building block servo to rotate to about 120°;
xxxxxxxxxxwhile True:if button_a.is_pressed():superbit.servo270(superbit.S1, 180)microbit.sleep(500)superbit.motor_control(superbit.M1, 255, 0) superbit.motor_control(superbit.M3, 255, 0) microbit.sleep(2000) superbit.motor_control(superbit.M1, 0, 0) superbit.motor_control(superbit.M3, 0, 0) superbit.servo270(superbit.S1, 60) microbit.sleep(500) superbit.servo270(superbit.S1, 120) microbit.sleep(500) superbit.motor_control(superbit.M1, -255, 0) superbit.motor_control(superbit.M3, -255, 0) microbit.sleep(2000) superbit.motor_control(superbit.M1, 0, 0) superbit.motor_control(superbit.M3, 0, 0)while True: infinite loop
In the infinite loop, determine whether the A button on the microbit mainboard is pressed. If the A button is pressed, the servo turns to 120° (the shovel is placed flat) -> forward 2 seconds -> the servo turns to 60° (the shovel is unloading) -> the servo turns to 120° (the shovel is placed flat) -> backward 2 seconds.
5. Write and download the program
- Open the Mu software and enter the code in the editing window. Note! All English and symbols should be entered in English mode, use the Tab key for indentation, and the last line ends with a blank program.
- Click the thumb 'Check' button to check if there are any errors in our code. If a cursor or underline appears in a line, it means a syntax error. Please check and modify it. If there is no error, the lower left corner will prompt that there is no problem with the detection.

- Click the 'REPL' button to check whether the Superbit library has been downloaded. If not, please refer to [Preparation before class] --> [2.4 Python Programming Guide] .

- After the program is written, connect the computer and microbit mainboard with a microUSB data cable, and click the 'Flash' button to download the program to the micro:bit mainboard. (You need to click the 'REPL' button again and turn off the import library file function before you can download the program normally).

- If the download fails, please confirm whether the microbit is properly connected to the computer via the microUSB data cable and the Superbit Python library has been imported.
6. Experimental phenomenon
After the program is successfully downloaded, the micro:bit dot matrix will display a smiley face, as shown in the figure below. Turn on the power switch, and the servo will initialize to 120° (flat). Press the A button of the micro:bit, the shovel of the car is lifted -> forward 2 seconds -> unload the goods -> shovel flat -> back 2 seconds.

If you need to restart, please press the reset button on the back of the micro:bit motherboard.