Data programming blocks are designed to process data passed to them through data wires and to send output to other programming blocks through their output plugs. There are a total of seven different Data programming blocks, each of which is reviewed in the sections that follow.
The Logic Block
The Logic block, shown in Figure 8.18, performs a logical operation on two input values. The input values can be specified in the block’s configuration panel
Figure 8.17
or supplied via data wire. The Logic block outputs a logical (True/False) value through its output plug.
As shown in Figure 8.19, the Logic block has a single attribute named Operation. In most cases, input values will be passed to the block via data wire. However, you can assign input values of True or False by selecting the check (True) or cross (False) for both of the block’s input values on the configuration panel. In addition, using the drop-down list located in the upper right corner of the configuration panel, you can select one of the four following logical operations that will be used to process the data values.
n And. Outputs a value of True if both input values are true.
n Or. Outputs a value of True if either or both input values are true (default).
n Xor. Outputs a value of True if one input value is True and the other
value is False. Outputs a value of False if both input values are True or both input values are False.
Figure 8.18
The Logic block performs a logical comparison on its input data.
Figure 8.19
n Not. Inverts a logical value (used when only one value is received as
input).
To help demonstrate how this data programming block works, look at the example shown in Figure 8.20. Here, logic data from the Sound and Light sensor blocks is passed to a Logic block where it is analyzed. If either of these sensor block’s logic data is True, a value of True is output by the Logic block. When received by the Move block, a value of True sets the robot’s direction to forward and a value of False sets the robot’s direction to backward.
The Math Block
The Math block, shown in Figure 8.21, performs a mathematical calculation using the two input values passed to the block, as indicated by the graphic symbol displayed on the block’s icon. The input values can be specified in the block’s configuration panel or supplied via data wire. The Math block outputs the two values as well as a number representing the result of the block’s calculation.
As shown in Figure 8.22, the Math block has a single attribute named Operation. In most cases, input values will be passed to the block via data wire. However, you can assign input values by typing values into the A and B entry fields.
Figure 8.20
The Logic block is used to process data from two sensor blocks, and its output is sent to the Move block, where it is used to set the robot’s direction.
Using the drop-down list located in the upper right corner of the configuration panel, you can select one of the six following mathematical operations that will be used to process the data values.
n Addition. Adds the two numeric values together (default). n Subtraction. Subtracts the second value from the first value. n Multiplication. Multiplies the two numeric values.
n Division. Divides the first numeric value by the second numeric value. n Absolute Value. Calculates the absolute value of a single value (used
only when the block is given a single value to process).
n Square Root. Calculates the square root of a single value (used only
when the block is given a single value to process).
The Compare Block
The Compare block, shown in Figure 8.23, determines if one input is greater than, less than, or equal to another input, as indicated by the graphic symbol displayed on the block’s icon. The input values can be specified in the block’s
Figure 8.21
The Math block performs basic mathematical operations on input data.
Figure 8.22
configuration panel or supplied via data wire. The Compare block outputs the two values as well as a logical value representing the result of its comparison. As shown in Figure 8.24, the Compare block has a single attribute named Operation. In most cases, input values will be passed to the block via data wire. However, you can assign input values in the form of two numbers by typing values into the A and B entry fields.
Using the drop-down list located in the upper right corner of the configuration panel, you can select one of the three following comparison operations that will be used to process the data values.
n Less Than. Determines whether the first value is less than the second
value (default).
n Greater Than. Determines whether the first value is greater than the
second value.
n Equals. Determines whether the two values are equal.
To help demonstrate how this data programming block works, let’s look at the example shown in Figure 8.25. Here, logic data from the Light sensor block is
Figure 8.23
The Compare block determines if one input is greater than, less than, or equal to another input.
Figure 8.24
passed to a Compare block where it is analyzed. If the Light Intensity value supplied by the Light sensor is less than 50, a value of True is sent to the Move block. Otherwise, a value of False is sent. When the Move block receives a value of True through the data wire, it sets the robot’s direction to forward. When a value of False is received, the robot’s direction is set to backward.
The Range Block
The Range block, shown in Figure 8.26, determines if a number is inside or outside of a range of numbers, as indicated by the graphic symbol displayed on the block’s icon. The input value can be specified in the block’s configuration panel or supplied via data wire. The Range block outputs the number as well as a logical value representing the result of its comparison.
As shown in Figure 8.27, the Range block has two attributes: Operation and Test value. In most cases, an input value will be passed to the block via data wire.
Figure 8.25
The Compare block is used to process data from the Light sensor block, and its output is sent to the Move block, where it is used to set the robot’s direction.
Figure 8.26
However, you can assign an input value by typing it in the Test value entry field. The range against which the input value is compared can be supplied via data wires (not shown by default on the Range block), or they can be supplied by the Operation attribute. When configuring this attribute, you can choose between determining whether the input value is inside (default) or outside the range. To specify the range, you can either type its upper and lower values in the two entry fields or use the slider control to specify them.
The Random Block
The Random block, shown in Figure 8.28, generates a random number within a specified range. The upper and lower ends of the range can be specified in the block’s configuration panel or supplied via data wire. The Range block outputs numbers representing the upper and lower range as well as its randomly generated number from within that range.
As shown in Figure 8.29, the Random block has a single attribute named Range. Minimum and Maximum range values can be passed to the block via data wire, or they can be specified as part of the Range attribute by typing them into the A and B entry fields. Alternatively, these values can be specified using the slider control located beneath the entry fields.
Figure 8.27
The Range block’s configuration panel.
Figure 8.28