$$ \newcommand{\floor}[1]{\left\lfloor{#1}\right\rfloor} \newcommand{\ceil}[1]{\left\lceil{#1}\right\rceil} \renewcommand{\mod}{\,\mathrm{mod}\,} \renewcommand{\div}{\,\mathrm{div}\,} \newcommand{\metar}{\,\mathrm{m}} \newcommand{\cm}{\,\mathrm{cm}} \newcommand{\dm}{\,\mathrm{dm}} \newcommand{\litar}{\,\mathrm{l}} \newcommand{\km}{\,\mathrm{km}} \newcommand{\s}{\,\mathrm{s}} \newcommand{\h}{\,\mathrm{h}} \newcommand{\minut}{\,\mathrm{min}} \newcommand{\kmh}{\,\mathrm{\frac{km}{h}}} \newcommand{\ms}{\,\mathrm{\frac{m}{s}}} \newcommand{\mss}{\,\mathrm{\frac{m}{s^2}}} \newcommand{\mmin}{\,\mathrm{\frac{m}{min}}} \newcommand{\smin}{\,\mathrm{\frac{s}{min}}} $$

Prijavi problem


Obeleži sve kategorije koje odgovaraju problemu

Još detalja - opišite nam problem


Uspešno ste prijavili problem!
Status problema i sve dodatne informacije možete pratiti klikom na link.
Nažalost nismo trenutno u mogućnosti da obradimo vaš zahtev.
Molimo vas da pokušate kasnije.

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 input category contains blocks (commands), which process data obtained from users (by clicking buttons) or the environment (by reading sensory data).

_images/p8.png

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 onstart block be executed?

  • once.
  • Bravo! The onstart block is one of the blocks from the Basic category, and blocks within it are executed only once during the running of the program.
  • an infinite number of times.
  • The forever block is the block within which commands will be executed an infinite number of times. The running of this block will never stop on its own. To stop the running of this block, you need to press the stop button (|stop|).

As we have already seen in the examples from the previous lesson, how the program starts and runs depends on which block was applied, onstart or forever.

In order to enable data entry, that is, to use button A to start or run the program, we need to select the onbutton from the input category, and from its drop-down list we need to choose the button A.

The block onbutton 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 shownumber from the category Basic.

After connecting these two blocks, we will select the block temperatura from the Input category, which we will drag into the input field of the show number command. The block temperatura stores the value received from reading the temperature sensor, which is displayed in degrees Celsius.

The final look of the program:

_images/p10.png

We will use the simulator to test the program. The program will run after the play button is clicked.

    Q-3: What will be the trigger for displaying the light level:

    _images/p11.png

    Little help: The block level stores the value received from the light sensor located on the display (LEDs play the role of the light sensor).

  • When button A is pressed, the value of the light level will be displayed.
  • Bravo! Pressing button A will display the value of the light level.
  • When button B is pressed, the value of the light level will be displayed.
  • The answer is not correct! Pressing button A will display the value of the light level.
  • When A and B are pressed at the same time, the value of the light level will be displayed.
  • The answer is not correct! Pressing button A will display the value of the light level.

    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)?

    _images/p16.png
  • Block A.
  • The answer is not correct!
  • Block B.
  • The answer is not correct!
  • Block C.
  • The answer is correct.
  • Block D.
  • The answer is not correct!

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

    _images/p17.png
  • When button A is pressed, the direction will be displayed.
  • The answer is not correct!
  • When button B is pressed, the direction will be displayed.
  • The answer is not correct!
  • When A and B are pressed at the same time, the direction will be displayed.
  • The answer is correct.

Task. Create a program, which should display a Smiley face (by using showleds) 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