Mathematics
General
In Blockly, you have the ability to perform various mathematical operations. You can calculate with numbers, generate random numbers, and map values to a different range.
Calculating Numbers
In Blockly, you can perform various mathematical calculations. The following blocks are available for this purpose:
Block | Function |
---|---|
A number. | |
Simple mathematical operationen. | |
A number. | |
Trigonometric functions. | |
Mathematical constants. | |
Check numbers. | |
Add a specific value to a number. | |
Round a number. | |
Get the remainder of a division. | |
Limit the range of a number. |
Random Numbers
In Blockly, you can generate random numbers. There are two different blocks available for this purpose.
With the integer random value
block, you can generate an integer random value within a defined range.
With the random number (0.0-1.0)
block, you can generate a random decimal number between 0.0 and 1.0.
Mapping Values
With the Map Value
block, you can map numbers, such as measurement values, to a new range. This is useful when you want to convert your measurement values directly into a percentage between 0 and 100, for example.
In the block sections, you need to set the boundaries of the original range and the boundaries of the new range using the number
blocks.
In the following example, the entire range of the light sensor (from 3 to 200,000 lux) is mapped to a new range from 0 to 100.