
Arduino is a electronic development and programming platform which allows different types of projects to be carried out through a plate correctly installed, Therefore, it is necessary to be able to know everything the programming environment of the same. It's worth mentioning that this is the difficult part of all this, so programming knowledge will depend mainly on the programs that they have.
These arduino boards like any other programming language It will have a large number of operators, functions, variablesAmong other things, this whole field can be very extensive, which is why we will mainly refer to the most important variables when programmingThese may vary depending on the programming level that you want to obtain.
Bearing in mind that knowing each of these factors will help you in the use and management of this platform for the development of each of your projectsHere we're going to show you that These are the Arduino variables, What are they for and which are the most important ones?To do this, carefully follow everything we will teach you below in the post.
What are Arduino programming language variables and what are they used for?
Variables are the place where you can store a piece of data. You have name, a value and a type. In the case of variable names, these can contain letters, numbers and symbolsThey should mostly begin with a letter, although they can also start with "_" However, this is not highly recommended since the criterion uses library routines.
These names can also include upper case and lower caseIn C, uppercase and lowercase letters are distinguished. Generally, the variables always they go in lowercase letters and uppercase constantsThis being the most normal thing in these cases.
They use the same rules within the code for appointment of the variables, either in lowercase but with words separated by underscores, as many as necessary to improve their readability or use conversions “CapWords” (Words that begin with a capital letter). However, the most common practice in these cases is to use a lowercase first word.
The use of a single underscore as a prefix for non-public methods and instance variables. Regarding names to avoid, it's important to never use the characters “L” the lowercase letter l and “O” the uppercase letter o or “I” the uppercase letter i as simple characters for variable names, since this can lead to cause confusion when reading the code.
Structure of a variable in Arduino: What are all its parts and what does each one contain?
As has been mentioned, variables are one of the ways to store a value, They have a name and are of only one type. These variables can mostly be used for many things such as checks, mathematical operations, among others.
Furthermore, it has a structure which we explain below:
Declaration
It should be emphasized again that the variables have a name, a value, and a typeWith the allocation, it is possible change the value of the variable if desired. All variables must be declared before they are used. Therefore, declarations must appear at the beginning of each function or block of statements. When declaring a variable, it will be necessary to first indicate the type of variable and then its name. Optionally, it is also possible to give it a value, which is called initializing the variable.
In the case of the declaration, it consists of a variable type and a list of variables separated by it, such as the following:
Int i,j; Unsigned long length, counter; Float x,pj;
Variables can be initialized in the declaration:
Unsigned long counter=0; Float pi=3.1416;
It is also possible to use the const modifier to indicate that the variable cannot be changed at runtime:
Const float e=2.7182
It's important to know that the declaration of a variable This can only be done once in the program. However, the value of the variable can be changed at any time simply by using arithmetic and various resignations.
The variables can become declared in a number of places within the program and with respect to the location where said declaration is made. All of this will determine in which part of the program it can be used, all of this will be called variable scopewhich we will explain later.
In relation to C and C ++ They are said to be statically typed languages, which means that type checking is executes during the compilation and not during executionThis way, the type of a variable cannot be changed at runtime. In the case of other, generally interpreted, languages, which are dynamically typed, the same variable can take on values of different types at different times, as is the case with... Python or PHP.
Ambit
Variables can be declared at the beginning of the program before the part of the setup() configuration, locally within functions, and sometimes within a block, as for loops of the type iF..for.. etcThe scope of application, or the ability of certain parts of a program to use it, will be determined by where the variable is declared.
Global variables are those that can be seen and used by any function and script in a program. As already mentioned, this type of variable must be declared at the beginning of the program, right before the setup. Similarly, it should be remembered that when declaring a global variable, is in a permanent memory space within a static zone Data and the overuse of global variables represent an inefficient use of memory.
Local variables are those that They are defined within a function or as part of a loopThese are only visible and can only be used within the function in which it was declaredIn this way, it is possible to have two or more variables with the same name in different parts of the same program where they can... contain different valuesHowever, it should be mentioned that this practice is not highly recommended because it makes the code harder to read.
The modifier of the static variable It is used to design variables that are only visible within a function. However, unlike local variables that are created and destroyed each time the function is called, the static variables It is characterized by maintaining its values between function calls.
Constants
In programming, a constant is a value that cannot be modified or altered during the execution of a program; therefore, it must remain constant throughout. fixed time, In this way it can only be read. Similarly, a constant corresponds to a fixed length of a reserved area in the computer's main memory, where the program typically stores fixed values. For example, it could be PI value = 3.1416.
In the case of const modifier, the behavior of a variable is modified by making it “read-only”, This means it can be used like any other variable, but in this case its value cannot be changed. In the environment of the arduino programming There are also predefined constants or expressions that make it easier code readings.
En C++ Constants can also be defined at the module level before compiling, so they don't occupy memory and their name can be replaced by the value defined in the compilation processThese constants are mostly written by names with capital letters and underscores separating words.
List of the main variables of the Arduino programming language that you should know
Currently, you can find different Arduino programming language variables.
The data stored in variables can be of different types, which we will show you below:
- Tank: They are mainly used to store characters, these can be letters and have to be either “” or ´´, char letter = “a”; , Char letters = “2”.
- Byte: In the case of bytes, numbers between 0 and 255 can be stored, and it has a numerical range of 8 bits.
- Int: These occupy 2 bytes (16 bits) and therefore store numbers between 2x -15 and 2x 15 – 1, that is, between -32,768 and 32,767.
- Long: It occupies 32 bits (to bytes) and has a range from -2,147,483,683 to 2,147,483,647.
- Unsigned int: This also occupies 2 bytes, but since it does not have a sign it can have values between 0 and 2×16 -1, that is, between 0 and 65,535.
- Double: It is also characterized by storing decimal numbers, but it has 8 bytes (64 bits).
- Floats: These are decimal numbers that occupy 32 bits, that is, 4 bytes; these can take values between -3.4028235E+38 and +3.4028235E+38.
You should keep in mind that whenever you choose a data type, you should choose the one that requires the least amount of space and that covers the required needssince these would occupy space in the memory of the Arduino board and could cause the program requires more memory of which it already has available.
















