Welcome to Building:bit Superkit repository
3.2 Changing Face
Changing Face
Changing Face1. Learning Objectives2. Building Blocks3. Sensor Wiring4. Programming4.1 Add expansion package4.2 Building blocks used4.3 Combining blocks5. Experimental phenomenon
1. Learning Objectives
In this course, we mainly learn how to make the Face Changing King through MakeCode graphical programming.
2. Building Blocks
For the building block steps, please refer to the installation drawings of [Assembly Course]--[Changing Face] or the building block installation album in the materials.
3. Sensor Wiring
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 ultrasonic wave is connected to the P1P2 pin.

! Notes:
When taking the course related to the building block servo for the first time, we need to remove the white building blocks 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 mask of the face-changing king to the closed state, as shown in the figure below, and then install the building blocks. (If you have used the program related to the face-changing king and the servo before, you can skip this step)

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 Yahboom software package https://github.com/YahboomTechnology/SuperBitLibV2, and you can start programming.
Method 2 Offline programming:
Open the offline programming software MakeCode and enter the programming interface. Click [New] and add the Yahboom software package https://github.com/YahboomTechnology/SuperBitLibV2 to start programming.
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 Combining blocks
The summary program is shown in the figure below.

You can also directly open the ChangingFace.hex file provided in this experiment and drag it into the browser that opens the URL, and the program diagram of this project source code will be automatically opened.
5. Experimental phenomenon
After the program runs successfully, turn on the power switch, the screen displays the heart icon, and initializes the servo to 0°, and executes the following program in an infinite loop:
① When the ultrasonic module recognizes that the distance is less than 10cm, the servo will be initialized to 50° (the Face Changing King mask is closed), and the dot matrix displays the "angry" icon. After 500 milliseconds, the servo will turn to 140° (the Face Changing King mask is open);
② When the ultrasonic module recognizes that the distance is greater than 100cm, the servo will be initialized to 50° (the Face Changing King mask is closed), and the dot matrix displays the "sleeping" icon. After 500 milliseconds, the servo will turn to 140° (the Face Changing King mask is open);
③ Otherwise, the "happy" icon is displayed.