Working with Blocks from the Input Category¶
The computer processes the data it receives from the input (from the user (pressing a button,…) or the environment (values obtained by sensor readings)). In MakeCode, there is a category of blocks which enables working with input data, more specifically a block category that allows a program to “perform certain actions” based on the information it receives from the user or the environment.
The category contains blocks (commands), which process data obtained from users (by clicking buttons) or the environment (by reading sensory data).

The input data can be obtained from pressing the button A
, B
or A+B
, as well as from reading the values of the sensors for light, temperature, and the accelerometer.
We want to create a program which displays the temperature (in degrees Celsius) when button A
is pressed.
Q-2: How many times will the blocks inside of the block be executed?
As we have already seen in the examples from the previous lesson, how the program starts and runs depends on which block was applied, or
.
In order to enable data entry, that is, to use button A
to start or run the program, we need to select the from the
category, and from its drop-down list we need to choose the button A.
The block starts the program and all blocks included in it are executed.
We drag the on button ... pressed
block onto the work surface, and then we insert in it the block which will allow us to display the value of the temperature.
For displaying the temperature, we will use the block from the category
.
After connecting these two blocks, we will select the block from the Input category, which we will drag into the input field of the show number command. The block
stores the value received from reading the temperature sensor, which is displayed in degrees Celsius.
The final look of the program:

We will use the simulator to test the program. The program will run after the button is clicked.
Q-3: What will be the trigger for displaying the light level:

Little help: The block stores the value received from the light sensor located on the display (LEDs play the role of the light sensor).
Q-4: Look carefully at the blocks. Which of the blocks represents a program that will draw a flower when a movement is made (shake)?

Q-5: Look carefully at the block. What will be the trigger (input) for displaying the direction of the placement of the device:

Task. Create a program, which should display a Smiley face (by using ) when button A is pressed, when button B is pressed it should show your names, and when A and B are pressed together, it should display how old you are.
You can compare your solution with ours: https://makecode.microbit.org/_86uV0j7mt0hU