Welcome to Mini Microbit Handle repository
11.Mobile shooter handle control
Microbit handle control
Microbit handle control1. Learning objectives2. Building blocks3. Motor wiring4. Code analysis4.1 Catapult4.2 Handle5. Write and download the program6. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to use Python programming to remotely control the catapult with the micro:bit handle.
2. Building blocks
For the building blocks steps, please refer to the installation drawings of [Assembly course]-[Mobile shooter] in the materials or the building blocks installation album.
3. Motor wiring
Insert the motor wiring on the left side of the car into the M1 interface of the Super:bit expansion board, and the black wire is close to the battery side;
Insert the motor wiring on the right side of the car into the M3 interface of the Super:bit expansion board, and the black wire is close to the battery side;
Insert the building blocks servo wiring 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 in the figure below:

! Notes:
When taking a course related to the building block servo for the first time, we need to remove the large gear installed on the servo 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 car projection rod to be parallel to the ground, and then install the servo gear. (If you have used the catapult and servo related programs before, you can skip this step)

4. Code analysis
4.1 Catapult
For the program, please refer to the Mobile shooter code.py file.
from microbit import *import superbitimport radioimport neopixelFirst, import the libraries needed for this lesson from microbit: the superbit library is dedicated to the superbit expansion board; neopixel is used to control RGB lights; radio is used for the wireless communication function of micro:bit.
xRed = (255, 0, 0)Orange = (255, 165, 0)Yellow = (255, 255, 0)Green = (0, 255, 0)Blue = (0, 0, 255)Violet = (148, 0, 211)White = (255, 255, 255)color_lib = { 'Red': Red, 'Orange': Orange, 'Yellow': Yellow, 'Green': Green, 'Blue': Blue, 'Violet': Violet, 'White': White}def RGBLight_more_show(first, num, color): global np np.clear() for i in range(first, first + num): np[i] = color_lib[color] np.show()This section of the program is used to define different colors of RGB lights, and define the function RGBLight_more_show to control the color of the RGB light. This function will be called in the following main loop.
xxxxxxxxxxnp = neopixel.NeoPixel(pin12, 4)