Constant Block
Constant Block
The Constant block lets you enter a value that you can use in several different places in your
program. If you change the value of the constant, all places where you use the constant will get the
updated value.
USING A CONSTANT
Mode Selector
Output
Variable Block
The Variable block lets you read or write a Variable in your program. You can also create a new
Variable and name it.
A Variable is a location in the memory of the EV3 Brick that can store a data value. You can write
to a Variable to store a data value. Later in the program, you can read from the Variable to access
the stored value.
Each variable has a Type and a Name. The different Types are Numeric, Logic, Text, Numeric Array, and Logic Array. You can choose
the Name of the variable, which is used to identify the variable.
The value of a variable can be changed while a program is running. Each time you write to a variable, any previous value is erased
and replaced with the new value. For example, you could use a variable named “Max Light” to keep track of the highest light
intensity that your robot has measured from the Color Sensor so far. Each time the robot detects a higher value, it could write the
new value into the “Max Light” variable.
ADDING A NEW VARIABLE
Mode Selector
Variable Selector
Value Input
Array Operations Block
The Array Operations block does operations on the Numeric Array and Logic Array data types.
You can create an array, add elements, read and write individual elements, and get the length of an
array.
Mode Selector
Inputs
Output
LOGIC OPERATIONS
Mode Selector
Inputs
Output
Choose the Logic operation you want to use by selecting a mode with the Mode Selector. The block will calculate the Result based on
the Inputs, as shown in this table.
A True if A is False,
NOT False if A is True
Math Block
The Math block does a math calculation on its inputs, and outputs the result. You can do a simple
math operation with one or two inputs, or enter a formula with up to four inputs.
Mode Selector
Inputs
Output
Choose the math operation you want to use by selecting a mode with the Mode Selector. After selecting the mode, you can choose
values for the inputs. The inputs available will change depending on the mode.
SIMPLE MATH OPERATION MODES
The simple math operation modes calculate the Result with a single math operation using one or two Inputs. These modes are shown
in the table below.
A, B A+B
Add
A, B A–B
Subtract
A, B A×B
Multiply
A, B A÷B
Divide
A A if A ≥ 0 -A if A < 0
Absolute The result is always ≥ 0.
Value
A √A
Square Root
A (base), N AN
Exponent (Exponent)
Round Block
The Round block rounds a decimal number to an integer value. You can round a number up, down,
or to the nearest integer. You can also truncate a number to a certain number of decimal places.
Mode Selector
Inputs
Output
Use the Mode Selector to choose the type of rounding to use. The different modes are described below.
MODES
Round To Nearest
The Round To Nearest, Round Up, and Round Down modes round a decimal number in the Input to an integer value in the Result.
Round To Nearest uses standard rounding rules to round to the nearest integer. Round Up always rounds up, and Round Down
always rounds down.
Round Up
The Round To Nearest, Round Up, and Round Down modes round a decimal number in the Input to an integer value in the Result.
Round To Nearest uses standard rounding rules to round to the nearest integer. Round Up always rounds up, and Round Down
always rounds down.
Round Down
The Round To Nearest, Round Up, and Round Down modes round a decimal number in the Input to an integer value in the Result.
Round To Nearest uses standard rounding rules to round to the nearest integer. Round Up always rounds up, and Round Down
always rounds down.
This table shows example output results.
1.2 1 2 1
1.5 2 2 1
1.7 2 2 1
2.0 2 2 2
2.1 2 3 2
Truncate
The Truncate mode lets you eliminate any digits past a specified decimal place in a decimal number. Any digits past the Number of
Decimals in the Input are eliminated in the Result. No other digits are affected (the output is not rounded).
This table shows example output results.
1.253 0 1
1.253 1 1.2
1.253 2 1.25
1.253 6 1.253
Compare Block
The Compare block compares two numbers to find out whether they are equal, or which number is
greater. You can choose one of six different comparisons. The output result is True or False.
COMPARE MODES
Mode Selector
Inputs
Output
Choose the type of comparison you want to use by selecting a mode with the Mode Selector. The block will calculate
the Result output by comparing the two inputs A and B as shown in the table below.
Range Block
The Range block tests whether a number is inside or outside a specified numerical range. The
output result is True or False.
Mode Selector
Inputs
Output
Use the Mode Selector to choose whether to test if a number is Inside or Outside a range. The Range block compares the Test
Value input to the range specified by the Lower Bound and Upper Bound inputs. The Result will be set to True or False, based on the
result of the comparison.
MODES
Inside
The Inside mode sets the Result to True if the Test Value is inside the specified range.
Outside
The Outside mode sets the Result to True if the Test Value is outside of the specified range.
Text Block
The Text block can combine up to three text strings into one text string.
Mode Selector
Inputs
Output
Random Block
The Random block can output a random Numeric or Logic value. You can use the result of the
Random block to make your robot randomly choose from different actions.
CHOOSE THE OUTPUT TYPE
Mode Selector
Inputs
Output
Use the Mode Selector to choose whether to output a random Numeric value or a random Logic value. After selecting the mode, you
can choose the Inputs. The inputs control the range and probability of the Value output.
Modes: Numeric , Logic
MODES
Numeric
The Numeric mode outputs a random integer value. The Value will be set to a random integer that is within the range specified by
the Lower Bound and Upper Bound. Each integer value within this range is equally likely to be chosen.
Example
This program makes a continuous series of tones of random frequencies in the range of 500 to 5000 Hz.
Logic
The Logic mode outputs a True or False value. The probability that a True value will be output is specified by the Probability of
True input. This input is a percentage value from 0 to 100. For example, a probability of 25 would result in a 25% chance that True
is output and a 75% chance that False is output.
Example
This program makes the robot choose
randomly between turning left and turning right, with a 50/50 chance of each.
See Using the Gyro Sensor for more information about what the Gyro Sensor does, the data that it
provides, and programming examples.
Port Selector
Mode Selector
Inputs
Outputs
Use the Port Selector on the top of the block to make sure that the sensor port number (1, 2, 3, or 4) matches the port on the EV3
Brick that the Gyro Sensor is connected to.
Use the Mode Selector to select the mode for the block. The Inputs and Outputs available will change depending on the mode.
MODES
Measure – Angle
The Measure – Angle mode outputs the rotation angle in Angle. The angle is measured relative to the last time the sensor was reset.
Use the Reset mode to reset the angle to 0.
Measure – Rate
The Measure – Reflected Light Intensity mode outputs the light intensity in Light."
See programming example 2 in Using the Gyro Sensor.
The Measure – Angle and Rate mode outputs the rotation angle in Angle and the rotation rate in Rate.
Compare – Angle
The Compare – Angle mode compares the rotation angle to the Threshold Value using the selected Compare Type. The True/False
result is output in Compare Result, and the rotation angle is output in Angle.
Compare – Rate
The Compare – Rate mode compares the rotation rate to the Threshold Value using the selected Compare Type. The True/False
result is output in Compare Result, and the rotation rate is output in Rate.
Reset
The Reset mode resets the rotation angle of the sensor to 0 (zero). Measurements of the rotation angle measure the motion relative
to the last time the sensor was reset.
My Block Builder
Sometimes you make a great mini-program that you want to use again in another Project or Program.
The My Block Builder helps you take this mini-program, which is a number of blocks you select in the work area, and group them
together to create a My Block.
Over time you may develop a library of My Blocks that you can trade with other MINDSTORMS users.