Professional Documents
Culture Documents
Resumen C For Arduino
Resumen C For Arduino
charAt()
The charAt() function returns a character at a particular
position inside a string.
Syntax: string.charAt(int);
int is an integer representing an index of the String value.
Returns type: char
Concatenation
The concat() function appends one string to another (that
is concatenate in a defined order).
Syntax: string.concat(string2);
string2 is a string and is appended to the end of string.
Remember that, the previous content of the string is
overwritten as a result of the concatenation.
Returns type: int (the function returns 1 if the concatenation
happens correctly).
Extract and replace
The substring() function extracts a part of a string from a start
index (included) to another (not included).
Syntax: string.substring(from, to);
from is the start index. The result includes the content of the from
string element. to is the end index. The result doesn't include the
content of the end string element, it can be omitted.
Returns type: String
Replacement
The replace() function replaces a part of a string with another string.
Syntax: string.replace(substringToReplace,
replacingSubstring);
from is the start index. The result includes the content of a from string
element. to is the end index. The result doesn't include the content of
an end string element, it can be omitted. Remember that, the previous
content of the string is overwritten as a result of the replacement (copy it
to another string variable if you want to keep it).
Returns type: int (the function returns 1 if the concatenation
happens correctly).
static
When you use the static qualifier for a variable inside a function, this makes the
variable persistent between two calls of the function. Declaring a variable inside a
function makes the variable, implicitly, local to the function as we just learned. It
means only the function can know and use the variable.
volatile
When you use the volatile qualifier in a variable declaration statement, this
variable is loaded from the RAM instead of the storage register memory space of the
board. The difference is subtle and this qualifier is used in specific cases where your
code itself doesn't have the control of something else executed on the processor. One
example, among others, is the use of interrupts. We'll see that a bit later.
const
The const qualifier means constant. Qualifying a variable with const makes it
unvariable, which can sound weird.
Comparison expressions
There are six comparison operators:
• == (equal)
• != (not equal)
• < (less than)
• > (greater than)
• <= (less than or equal to)
• >= (greater than or equal to)
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
if (a < b) {
ledState = 1;
}
else if (b > 0) {
ledState = 0;
}
else {
ledState = 1;
}
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
if (a < b) { // a < b
ledState = 1;
}
else if (b > 0) { // a >= b and b > 0
ledState = 0;
}
else { // a >= b and b < 0
ledState = 1;
}