Welcome to Building:bit Superkit repository
3.9 Rocker carrier
Rocker carrier
Rocker carrier1. Learning objectives2. Building blocks3. Sensor wiring4. Code Analysis5. Write and download the program6. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to implement a joystick remote control transporter through Python programming.
2. Building blocks
For detailed steps of building blocks, please refer to the installation drawings of [Assembly Course]--[Rokcer transporter] in the materials or the building block installation album.
3. Sensor 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;
The joystick module is connected to the P1P2 interface.

4. Code Analysis
For the program of this course, please see the Rocker-carrier.py file.
from microbit import *import WOM_Sensor_Kitimport superbitFirst, import the libraries needed for this lesson from microbit: the superbit library is dedicated to the superbit expansion board; the WOM_Sensor_Kit library is used for sensors.
xxxxxxxxxxdisplay.show(Image.HAPPY)superbit.servo270_V2(superbit.S1, 120)sleep(500)Display a "smiley face" icon, initialize the S1 servo, and set it to 120 degrees
xxxxxxxxxxwhile True:if WOM_Sensor_Kit.WOM_rocker(pin1, pin2, WOM_Sensor_Kit.WOM_up):superbit.servo270_V2(superbit.S1, 180)sleep(500)elif WOM_Sensor_Kit.WOM_rocker(pin1, pin2, WOM_Sensor_Kit.WOM_down):superbit.servo270_V2(superbit.S1, 60)sleep(500)elif WOM_Sensor_Kit.WOM_rocker(pin1, pin2, WOM_Sensor_Kit.WOM_right): superbit.servo270_V2(superbit.S1, 120) superbit.motor_control(superbit.M1, 0, 0) superbit.motor_control(superbit.M3, 255, 0) sleep(500) superbit.motor_control(superbit.M1, 0, 0) superbit.motor_control(superbit.M3, 0, 0) elif WOM_Sensor_Kit.WOM_rocker(pin1, pin2, WOM_Sensor_Kit.WOM_left): superbit.servo270_V2(superbit.S1, 120) superbit.motor_control(superbit.M1, 255, 0) superbit.motor_control(superbit.M3, 0, 0)sleep(500)superbit.motor_control(superbit.M1, 0, 0)superbit.motor_control(superbit.M3, 0, 0)Detect the direction of the joystick in an infinite loop (connected to pin1 and pin2), and control the S1 servo angle and motor speed according to the direction. If it is upward, the servo turns to 180 degrees; if it is downward, the servo turns to 60 degrees; if it is left, the servo returns to the initial 120 degrees, and the M3 motor rotates forward at a speed of 255, and the M1 motor does not rotate; if it is right, the servo returns to the initial 120 degrees, and the M1 motor rotates forward at a speed of 255, and the M3 motor does not rotate.
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 whether 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, click the 'Flash' button to download the program to the micro:bit mainboard. (You need to click the 'REPL' button again to turn off the import library file function before you can download the program normally).

- If the download fails, please confirm whether the microbit is connected to the computer normally via the microUSB data cable and the Superbit Python library has been imported.
6. Experimental phenomenon
After the program runs successfully, the microbit dot matrix will display a smiley face. Turn on the power switch and the servo will initialize and level. When the rocker is moved upward, the shovel is lifted; when the rocker is moved downward, the shovel unloads the cargo; when the rocker is moved to the left, the shovel is reset and the trolley turns left; when the rocker is moved to the right, the shovel is reset and the trolley turns right.