The blocks. Structure and actions

The Blocks: Structure and Actions

Blocks are the basic programming units used in Clu-Blocks Pro to create a program.

Each block represents an instruction, operation, value, or function. Blocks are arranged and connected to create the sequence of instructions that the D1 R32 will execute.

In most block sequences, the program follows the connected instructions from top to bottom.


Structure of a Block

Blocks can contain different elements depending on their function.

The following figure shows the main parts that you may find in a block.

PartDescription
Block NameIdentifies the main function or purpose of the block.
ParametersValues or options used to configure how the block operates.
Input ConnectionsAllow values, variables, or other compatible blocks to be inserted into the block.
Block ConnectionsAllow compatible instruction blocks to be connected together.
Drop-down MenuAllows you to select one of the available options for a parameter.
Configuration IconAppears on certain blocks and provides additional configuration options.

Not every block contains all of these elements. The structure depends on what the block is designed to do.


Block Help

If you are not sure what a block does, place the mouse pointer over the block and leave it there for a few seconds.

When help is available for that block, a small information box will appear.

This provides a quick way to learn the purpose of a block without leaving the programming workspace.


Block Name

The Block Name identifies the main function of the block.

For example, a block may be designed to:

  • Read an input.
  • Control an output.
  • Perform a calculation.
  • Make a decision.
  • Display information.
  • Send information through the Serial Port.
  • Control a sensor or actuator.

Block names help you quickly identify the purpose of each instruction in your program.


Block Parameters

Parameters are values or options that determine how a block operates.

Depending on the block, a parameter may represent:

  • A pin.
  • A number.
  • A text value.
  • A variable.
  • A TRUE/FALSE value.
  • A time value.
  • An option selected from a drop-down menu.

Some parameters can be selected directly from a drop-down menu. Others can accept compatible value blocks or variables.

Using parameters allows the same type of block to perform different operations without requiring a different block for every possible value.


Block Context Menu

A block has several actions available through its Context Menu.

To open the menu:

  1. Place the mouse pointer over the block.
  2. Right-click the block.
  3. Select the required option.

The available options may depend on the selected block.

FunctionDescription
DuplicateCreates an identical copy of the selected block, including its current parameters.
Add CommentAdds a comment that can be used to explain the purpose of a block or section of the program.
External Inputs / Inline InputsChanges how the block parameters are displayed without changing the purpose of the block.
Collapse BlockReduces the visual size of the block to save workspace.
Expand BlockRestores a collapsed block to its complete view.
Disable BlockTemporarily prevents the block from participating normally in the program while keeping it in the workspace.
Enable BlockReactivates a previously disabled block.
Delete BlockRemoves the selected block and, when applicable, blocks connected as part of the selected structure.

Duplicating a Block

The Duplicate option creates a copy of the selected block.

The duplicated block keeps the same configuration and parameter values as the original block.

This is useful when you need to repeat a similar instruction without creating and configuring the block again.

After duplicating the block, you can modify its parameters if different values are required.


Adding Comments

Comments are useful for explaining what a block or section of a program is intended to do.

To add a comment, right-click the appropriate block and select Add Comment.

A comment box will appear where you can enter your explanation.

Comments are especially useful in larger programs because they help you remember the purpose of different sections of your code.

For example, a comment could identify a section such as:

Read the temperature sensor

or:

Send the sensor value to the PC

Comments are intended to explain the program and do not replace programming instructions.


External Inputs and Inline Inputs

Some blocks allow their parameters to be displayed in different ways.

The External Inputs / Inline Inputs option changes the visual arrangement of these parameters.

ModeDescription
Inline InputsParameters are displayed within the main horizontal structure of the block.
External InputsParameters are arranged externally, making complex blocks easier to view in some situations.

Changing between these layouts changes the appearance and organization of the block, not the purpose of the instruction.


Collapse and Expand Block

Large programs can contain many blocks and take up a considerable amount of workspace.

The Collapse Block option reduces the visual size of a block.

Collapse Block

Use Collapse Block when you want the block to occupy less space in the workspace.

Expand Block

Use Expand Block to restore the complete view of a collapsed block.

This can make large programs easier to navigate and organize.


Disable and Enable Block

Sometimes you may want to temporarily exclude a block while testing your program without deleting the block.

Use Disable Block to temporarily disable it.

When you want to use the block again, right-click the block and select Enable Block.

This is useful while testing different versions of a program because the block can remain in the workspace for later use.


Delete Block

The Delete Block option removes a block from the workspace.

Depending on the selected structure, connected blocks associated with that block may also be included in the deletion.

Always check what is selected before deleting a block or group of blocks.

If you delete something accidentally, use Undo or press:

Ctrl + Z


Functional Configuration of a Block

Some blocks provide additional configuration options that allow their structure to be expanded or modified.

These blocks contain a small configuration icon.

Clicking the configuration icon opens a configuration window where additional elements can be added to the block.

The If block is an important example.


Configuring an If Block

A basic If block performs an action only when a specified condition is true.

The block can be expanded by adding additional conditional structures.

Additional elements may include:

ElementPurpose
IfTests the first condition.
Else IfTests another condition when the previous condition was not satisfied.
ElseProvides instructions to execute when the previous conditions were not satisfied.

This allows a simple conditional block to be expanded into a more complex decision structure.

For example:

IF temperature is high
→ Turn on a fan

ELSE IF temperature is medium
→ Reduce the fan speed

ELSE
→ Turn off the fan

Other blocks may also provide additional configuration options.

[ INSERT IMAGE HERE: Other Configurable Blocks ]

Figure. Examples of other blocks that provide additional configuration options.


Embedding Parameters and Variables in a Block

Many blocks require additional information before they can perform their function.

For example, a block may need to know:

  • Which pin to use.
  • What value to write.
  • What number to compare.
  • What text to display.
  • Which variable to use.
  • What condition must be evaluated.

Compatible blocks can be inserted into the corresponding input areas.

The shape of an input helps indicate what type of block or value can be connected to it.

Only compatible elements can be connected correctly.


Working with Variables

Variables are an important programming concept in Clu-Blocks Pro .

A variable is used to store information that a program can use and, when necessary, change while it is running.

The blocks used to work with variables are located in the:

Variables category.

Variable blocks allow you to create variables, assign values, change values, and use stored values in other parts of your program.


Variable Types

Variables can store different types of information.

The required type depends on the information you want the variable to contain.

Variable TypeDescriptionExample
IntStores an integer, or whole number.25
FloatStores a number with a decimal value.23.5
BooleanStores one of two logical states: TRUE or FALSE.TRUE
StringStores text or a sequence of characters."Clu-Bot"

Examples

You could use an Int variable to store:

Number of button presses = 5

A Float variable could store:

Temperature = 23.5

A Boolean variable could represent:

Motion detected = TRUE

A String variable could contain:

Robot name = "Clu-Bot"


Creating and Assigning a Variable

Before using a variable, the program needs a variable with a name and a value.

For example:

temperature = 23

The variable name is:

temperature

and its current value is:

23

After the variable has been created, the stored value can be used by other blocks in the program.


Changing a Variable

A variable does not always need to keep the same value.

The program can assign a new value when necessary.

For example:

counter = 0

After an event occurs:

counter = 1

After another event:

counter = 2

This makes variables especially useful for storing information that changes while the program is running.


Using a Variable

After a variable contains a value, the variable can be inserted into compatible blocks.

For example, instead of sending a fixed number to the computer, you could send the value stored in a variable.

This allows information collected in one part of the program to be used in another part.

For example:

Sensor → Variable → Serial Port → PC

A sensor reading can be stored in a variable and then sent through the Serial Port so you can observe the value on the computer.


Quick Reference

ConceptPurpose
BlockRepresents an instruction, function, operation, or value.
Block NameIdentifies the purpose of a block.
ParameterProvides information required by a block.
DuplicateCreates a copy of a block.
CommentAdds an explanation to the program.
Collapse / ExpandChanges the visual size of a block.
Disable / EnableTemporarily disables or reactivates a block.
DeleteRemoves a block from the workspace.
ConfigurationProvides additional structural options for certain blocks.
VariableStores information that can be used by the program.
IntWhole-number value.
FloatDecimal-number value.
BooleanTRUE or FALSE value.
StringText value.