Insert micro:bit into the edge connector of the expansion board. Note：micro:bit will always stay attached to the expansion board in the following sessions. Connect the LED module to the P1 port of the expansion board.
Task 1: Turn on the LED Open online programming interface of MakeCode.
STEP1: Start a new project. For specific operation, the STEP 3 in chapter 1 can be used as a reference.
STEP2: The external LED is used in the hardware connection. During the process of programming, the turning-on and turning-off of the light is controlled by setting the pin status of micro: bit. LEDs in this experiment belong to the digital output. Click on "Advanced" and there will be "Pins". The procedure for calling the instruction: Pins (advance) ----digital write pin p0 to (0). (After dragging the instruction, you should change P0 to P1)
STEP3: Drag the module into "forever" and upload the code. When the code is successfully uploaded to the micro: bit, the external LED connected to the P1 pin lights up.
Task 2: Flashing LED
Goal: After learning how to turn on a LED, we should learn how to make it blink.
STEP1: Start a new project. For specific operation, the STEP 3 in Chapter 1 can be used as a reference.
STEP2: Set the pin status of micro: bit to either turn on and off the LED. LEDs in this experiment belong to the digital output. Click the "Advance"->"Pins", set digital write pin p1 to (0). The pin value can only be 0 or 1. When it is 1, the light stays on. When it is 0, the light stays off.
Set the value of Pin P1 to high (1) and the LED will light
Set the value of Pin P1 to low (0) and the LED will turn off
STEP3: You will also need to keep the external LED on for 1 second and off for another second in a sequence. To do this, go to Basic and select Pause (ms) (100). The "Pause" command keep the same status for a certain period of time.
STEP4: The final code will show as below after dragging the "Pause" command to the "forever" and adjusting the numbers. In this picture: set “pin P1” as 1 (LED on) and “pause(ms)” as 1000, pin P2 as 2 (off) and “pause(ms)” as 1000, and the program inside the “forever” loop will be running repeatedly in a sequence.
Exercise Learn something about the principle of SOS emergency signal, share it with your classmates and try to program it!