Welcome to Building:bit Superkit repository
3.Micro:bit handle control
Micro:bit handle control
Micro:bit handle control1. Learning objectives2. Building blocks3. Motor wiring4. Programming4.1 Add expansion package4.2 Building blocks used4.3 Add new variables4.4 Combined blocks5. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to use MakeCode graphical programming to realize the microbit handle to control the airplane.
2. Building blocks
For the building block steps, please refer to the installation drawings of [Assembly Course]--[Airplane] in the materials or the building block installation book.
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 line is close to the battery side;
As shown below:
4. Programming
Method 1 Online programming:
First, connect the micro:bit to the computer via a USB data cable, and the computer will pop up a U disk. Click the URL in the U disk: https://makecode.microbit.org/ to enter the programming interface. Then, add the Yaboom software package to program.
Method 2 Offline Programming:
Open the offline programming software MakeCode and enter the programming interface. Click [New] and add the Yaboom software package to start programming.
superbit kit expansion package: https://github.com/YahboomTechnology/SuperBitLibV2 Handle expansion package: https://github.com/YahboomTechnology/GHBitLib
4.1 Add expansion package
4.2 Building blocks used
The location of the building blocks required for this programming is shown in the figure below.
4.3 Add new variables
① Find the [Variable] option in the building block bar ---- [Set variable]
② Enter the variable name to complete the new variable.
4.4 Combined blocks
The microbit summary program on Airplane is shown in the figure below
Handle Rocker control program is as follows
Handle gravity control program is as follows
You can also directly open the microbit-handle-control-airplane.hex、microbit-Handle-rocker-control.hex、microbit-Handle-gravity-control.hex Drag the file into the browser that opens the URL, and the program diagram of the source code of this project will be automatically opened
5. Experimental phenomenon
We need to download the Airplane program to the micro:bit motherboard of the Airplane, turn on the power switch of the Airplane, and we can see that the micro:bit dot matrix will initialize to display an airplane pattern, and then it will display the number 1 (indicating that it has entered the default mode 1).
Download the handle remote control program to the micro:bit motherboard of the handle, turn on the power switch of the handle, and we can see that the micro:bit dot matrix will initialize to display a heart pattern, and then it will display an "X" pattern, indicating that the handle is in the default state and no data is sent.
The two will automatically complete the pairing, and then we can start to remotely control the Airplane.
The handle functions are as follows.
Handle Rocker control:
After the Rocker and Airplane are paired successfully, we can see the number 1 displayed on the micro:bit dot matrix of Airplane, indicating that it is in mode 1.
In mode 1:
- Push the Rocker forward to control the propeller of Airplane to rotate counterclockwise, and it will stop rotating when you release your hand;
- Push the Rocker backward to control the propeller of Airplane to rotate clockwise, and it will stop rotating when you release your hand;
- Press the red button to light up the red RGB light;
- Press the green button to light up the green RGB light;
- Press the yellow button to light up the yellow RGB light;
- Press the blue button to light up the blue RGB light.
We can press the Rocker to switch to mode 2, and we can see the number 2 displayed on the micro:bit dot matrix of Airplane, indicating that it is in mode 2.
In mode 2:
- Push the Rocker forward to control the propeller of the Airplane to rotate counterclockwise, and it will keep rotating after releasing the hand;
- Push the Rocker backward to control the propeller of the Airplane to rotate clockwise, and it will keep rotating after releasing the hand;
- Press the red button to light up the red RGB light and stop the rotating propeller;
- Press the green button to light up the green RGB light;
- Press the yellow button to light up the yellow RGB light;
- Press the blue button to light up the blue RGB light.
Each time the Rocker is pressed, it will switch back and forth between mode 1 and mode 2, and the RGB light will go out.
Handle gravity control:
After the handle and Airplane are successfully paired, we can see the number 1 displayed on the micro:bit dot matrix of Airplane.
- Tilt the handle forward to control the propeller of the Airplane to rotate counterclockwise, and stop rotating when placed horizontally;
- Tilt the handle backward to control the propeller of the Airplane to rotate clockwise, and stop rotating when placed horizontally;
- Press the red button to light up the red RGB light;
- Press the green button to light up the green RGB light;
- Press the yellow button to light up the yellow RGB light;
- Press the blue button to light up the blue RGB light.
(Note: There is only one mode for the Handle gravity control, and you cannot switch to mode 2)