Branch "Code Element"
This branch is used to directly create a block code element.
Also, this branch is given the name of the code element and, if necessary, the condition for its insertion into the project code.
There are three options for selecting an insertion condition.
There are three options for selecting an insertion condition.
If you select The "no condition" option, the code is certainly inserted into the sketch if necessary.
In the other two cases, you must select the condition for inserting code into the sketch.
This is done using the "Select condition" button(2). this opens a window with a list of conditions available for this code element.
In the other two cases, you must select the condition for inserting code into the sketch.
This is done using the "Select condition" button(2). this opens a window with a list of conditions available for this code element.
With the selected condition, use the "Go to condition" button»(1), you can directly go to the settings branch of the selected condition.
If you select the "condition is true" option, the code will be inserted into the sketch only if the Boolean expression of the condition returns True. Accordingly, if the "condition is false" option is selected, the code will be inserted into the sketch only if the Boolean expression of the condition returns False.
The code editor toolbar depends on the location of this code element.
Consider the possible options.
If you select the "condition is true" option, the code will be inserted into the sketch only if the Boolean expression of the condition returns True. Accordingly, if the "condition is false" option is selected, the code will be inserted into the sketch only if the Boolean expression of the condition returns False.
The code editor toolbar depends on the location of this code element.
Consider the possible options.
General code of a multiblock, General code of a group of blocks, General code of a block - the Declare section.
With this arrangement of the code element in the toolbar, there are buttons "Insert UUID"(1), " Insert parameter tag»(2) and the check box "Prevent the compiler from seeing #Include"(3).
When you click on the "Insert UUID" button(1), the ID selection window opens.
When you click on the "Insert UUID" button(1), the ID selection window opens.
"A unique number" - "Unique number"each time this ID is selected, a unique number will be generated and inserted
into the code at the cursor location.
"Multiblock ID" - when this ID is selected, thetag is inserted into the code. When compiling the project, the multiblock ID will be inserted instead,
which will be the same in all the code included in this multiblock.
When you click on the "Insert parameter tag" button»(2) the tag selection window opens.
"Multiblock ID" - when this ID is selected, the
When you click on the "Insert parameter tag" button»(2) the tag selection window opens.
After selecting the from tag, it is inserted into the cursor position in the editor.
Check the box "Prevent the compiler from seeing a #Include»(3) present in the code element editor toolbar only when this element is located in the Declare section.
It is designed to control the project compiler. If it is not marked, the compiler will collect all the #Include lines from the Declare section of all instances of blocks and insert them into the sketch code in the place that it considers necessary,
obeying its own logic. Installing this check box tells the compiler that you can't touch the #Include line in this code element and you need to insert it into the sketch in the place where the block developer wrote it.
In some cases, this is necessary. For example, where the inclusion of one library should be made only after the inclusion of another, on which the first depends.
But in this case, it is possible to duplicate the connection of libraries. This is not terrible of course, but as they say – "not kosher".
General code of a multiblock, General code of a group of blocks, General code of a block – other sections.
General code of a multiblock, General code of a group of blocks, General code of a block – other sections.
With this arrangement of the code element in the toolbar, there are buttons "Insert UUID"(1), " Insert parameter tag»(2) and "Insert temporary variable tag"(3).
The operation of the "Insert UUID"(1) and "Insert parameter tag"(2) buttons was discussed above.
When you click "Insert a tag to a temporary variable»(3) the time variable type selection window opens.
The operation of the "Insert UUID"(1) and "Insert parameter tag"(2) buttons was discussed above.
When you click "Insert a tag to a temporary variable»(3) the time variable type selection window opens.
After selecting a tag, it is inserted into the editor at the cursor location.
Now consider what a temporary variable is. This is a variable that can be used by the block for intermediate calculations. When compiling a project, the compiler asks all blocks (both standard and custom) what type of temporary variable they need. After that, if necessary, it creates one variable of each requested type. That's just the name of this variable and will be inserted into the sketch when compiling instead of this tag.
Note that work with this variable must begin (write to it) and end within one section of the code. Because a block compiled after this block can write other values to this variable.
Now consider what a temporary variable is. This is a variable that can be used by the block for intermediate calculations. When compiling a project, the compiler asks all blocks (both standard and custom) what type of temporary variable they need. After that, if necessary, it creates one variable of each requested type. That's just the name of this variable and will be inserted into the sketch when compiling instead of this tag.
Note that work with this variable must begin (write to it) and end within one section of the code. Because a block compiled after this block can write other values to this variable.
Example of using a temporary variable.
Output unit to display the value of a variable.
This block, depending on the type of the selected variable, converts the value of this variable to a String and then displays it on the screen. In this block, 4 code elements are created in the Loop section of the code of each instance at the place where the block is inserted.
The first three are conditional and are inserted into the code depending on the type of the selected variable.
In these code elements, the converted value of the selected variable is written to a temporary variable of type String.
This block, depending on the type of the selected variable, converts the value of this variable to a String and then displays it on the screen. In this block, 4 code elements are created in the Loop section of the code of each instance at the place where the block is inserted.
The first three are conditional and are inserted into the code depending on the type of the selected variable.
In these code elements, the converted value of the selected variable is written to a temporary variable of type String.
In the fourth element of the code, we display the value of this time variable on the screen. This element is unconditional.
As a result of compilation, with the selected Boolean variable, we get the following code.
if (_gtv1)
{
_tempVariable_String = "Нет";
}
else {
_tempVariable_String = "Да"; }
if ((0))
{
myOLED.print(_tempVariable_String, 0, 0);
}
if (_gtv1)
{
_tempVariable_String = "Нет";
}
else {
_tempVariable_String = "Да"; }
if ((0))
{
myOLED.print(_tempVariable_String, 0, 0);
}
The code of each instance is the Declare section
With this arrangement of the code element in the toolbar, there are buttons "Insert UUID"(4), " Insert parameter tag»(1), " Insert login tag»(5), " Insert exit tag»(6) and the check box "Prevent the compiler from seeing #Include"(2).
Operation of the "Insert parameter tag" button»(1) and the box check "Prevent the compiler from seeing #Include"(2) we discussed above.
When you click the "Insert UUID" button (4) with this location of the code element, an extended ID selection window opens.
Operation of the "Insert parameter tag" button»(1) and the box check "Prevent the compiler from seeing #Include"(2) we discussed above.
When you click the "Insert UUID" button (4) with this location of the code element, an extended ID selection window opens.
A new item appeared in this window - "Instance ID".
When this option is selected, the tag is inserted into the cursor location in the code editor. When compiling a block in the project, the ID of a specific instance of the block is inserted instead.
Example
In the Declare section of each instance's code, we declare a variable.
And in the Loop section of each instance, at the place where the block is inserted, we write the value to it.
We insert two instances of this block into the project
As a result of compilation, we get the code:
Declare Section
int Var_176673836 ;
int Var_127258073 ;
Loop section where the first instance is inserted
Var_176673836 =200;
The Loop section is where the second instance is inserted.
Var_127258073 =200;
Declare Section
int Var_176673836 ;
int Var_127258073 ;
Loop section where the first instance is inserted
Var_176673836 =200;
The Loop section is where the second instance is inserted.
Var_127258073 =200;
When you click the "Insert input tag" buttons(5), "Insert output tag" (6) a window opens for selecting the appropriate tag from the list of inputs or outputs of this block.
After selecting the desired tag, it is inserted into the position of the cursor in the code editor.
Consider the operation of the login tag.
Unlike the old (Basic) custom block editor, this editor does not create variables for inputs. This is done to save the memory of the microcontroller. Instead of the input tag, a Boolean expression obtained from the input is inserted into the code, enclosed in parentheses. In most cases, this is the name of the output variable of the block connected to this input.
For example, consider this code
Consider the operation of the login tag.
Unlike the old (Basic) custom block editor, this editor does not create variables for inputs. This is done to save the memory of the microcontroller. Instead of the input tag, a Boolean expression obtained from the input is inserted into the code, enclosed in parentheses. In most cases, this is the name of the output variable of the block connected to this input.
For example, consider this code
When you connect a constant to the input, we get the following result.
if ((50) ==20)
{
// Какой то код
}
If we feed the input, output of a block with an output variable, we get the following.
{
// Какой то код
}
If we feed the input, output of a block with an output variable, we get the following.
if (((_d18x2x1O)) ==20)
{
// Какой то код
}
But at the input, math is also possible, which is calculated on the fly to save memory
For example, with this scheme, we get a more complex version.
{
// Какой то код
}
But at the input, math is also possible, which is calculated on the fly to save memory
For example, with this scheme, we get a more complex version.
if ((((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L))) ==20)
{
// Какой то код
}
With this use of the block input, this is not critical. But it is possible that the input is used as a parameter of some function in the library. Not all libraries "like" when they are given an expression as a parameter.
For example, let's rewrite the block code.
{
// Какой то код
}
With this use of the block input, this is not critical. But it is possible that the input is used as a parameter of some function in the library. Not all libraries "like" when they are given an expression as a parameter.
For example, let's rewrite the block code.
Get the result
Out_238022926_164280164 = abstractCrazyFunction((((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L))));
Function abstractCrazyFunction most likely, he will swear when he gets this as a parameter: ((((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L))).
Therefore, when you are not sure that the use of the input will be correct for any data coming to the input, I recommend using this construction.
Out_238022926_164280164 = abstractCrazyFunction((((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L))));
Function abstractCrazyFunction most likely, he will swear when he gets this as a parameter: ((((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L))).
Therefore, when you are not sure that the use of the input will be correct for any data coming to the input, I recommend using this construction.
Then the compilation result will satisfy any function..
_tempVariable_int = (((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L)));
Out_238022926_164280164 = abstractCrazyFunction(_tempVariable_int);
Out_142227144_164280164 = abstractCrazyFunction1(_tempVariable_int);
The code of each block is the remaining sections.
_tempVariable_int = (((((_d18x2x1O))+(100))*(85.00))-(((_d18x2x1O))*(45L)));
Out_238022926_164280164 = abstractCrazyFunction(_tempVariable_int);
Out_142227144_164280164 = abstractCrazyFunction1(_tempVariable_int);
The code of each block is the remaining sections.
Here are the buttons that we discussed earlier.