STEP1: Connect the push-button module to pin P0 of the expansion board; connect the fan module to pin P1.
STEP2: Programming
1. Click “micro: bit” module, select “read digital pin P0”, and drag it to script section.
2. The “=” in the “Operators” module can be used to judge whether the button is pressed. If the value of “read digital pin P0” is “1”, which suggests the button is pressed, otherwise, it is released. Nest the block “read digital pin P0” into the equation.
3. Find “if then…else” block in the “Control” module, and drag it into the “forever” block.
4. Nest the conditions of equation into the “if then…else” block as shown below.
5. Find the block “set digital pin P0 output LOW” in the “micro: bit” module. Revise the block into “set digital pin P1 output HIGH” and place it under “if then” block. When the button is pressed, this command will be executed and the fan starts to rotate. Otherwise, the fan stops rotating.
STEP1: Replace the push-button module in the button-fan project with switch knob module.
STEP2: Programming
1. Click “micro: bit”, drag “read analog pin P0” block to script section
2. Drag the “set analog pin P0 output” of the micro: bit module to the “forever” in the script area, revise P0 to P1, and nest the two blocks as shown below.