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 i