From b309ab7f11ce214fbfae37688a3dce950220fd1f Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 18 Feb 2019 20:48:23 -0800 Subject: [PATCH] Use Unix EOL in all files Use consistent EOL across all files, following the Unix EOL convention established by the reference example files. --- .../Functions/Characters/isUpperCase.adoc | 148 ++++----- .../Arithmetic Operators/addition.adoc | 178 +++++----- .../Arithmetic Operators/assignment.adoc | 140 ++++---- .../Arithmetic Operators/division.adoc | 172 +++++----- .../Arithmetic Operators/multiplication.adoc | 182 +++++----- .../Arithmetic Operators/subtraction.adoc | 182 +++++----- .../Bitwise Operators/bitshiftLeft.adoc | 242 +++++++------- .../Bitwise Operators/bitshiftRight.adoc | 194 +++++------ .../Bitwise Operators/bitwiseAnd.adoc | 166 +++++----- .../Bitwise Operators/bitwiseNot.adoc | 152 ++++----- .../Bitwise Operators/bitwiseOr.adoc | 162 ++++----- .../Bitwise Operators/bitwiseXor.adoc | 170 +++++----- .../Boolean Operators/logicalAnd.adoc | 128 ++++---- .../Boolean Operators/logicalNot.adoc | 144 ++++---- .../Boolean Operators/logicalOr.adoc | 132 ++++---- .../Compound Operators/compoundAddition.adoc | 136 ++++---- .../compoundBitwiseAnd.adoc | 238 +++++++------- .../Compound Operators/compoundBitwiseOr.adoc | 224 ++++++------- .../compoundBitwiseXor.adoc | 224 ++++++------- .../Compound Operators/compoundDivision.adoc | 142 ++++---- .../compoundMultiplication.adoc | 142 ++++---- .../Compound Operators/compoundRemainder.adoc | 156 ++++----- .../compoundSubtraction.adoc | 138 ++++---- .../Compound Operators/decrement.adoc | 148 ++++----- .../Compound Operators/increment.adoc | 144 ++++---- .../Structure/Control Structure/break.adoc | 130 ++++---- .../Structure/Control Structure/continue.adoc | 130 ++++---- .../Structure/Control Structure/doWhile.adoc | 148 ++++----- .../Structure/Control Structure/else.adoc | 164 ++++----- Language/Structure/Control Structure/for.adoc | 236 ++++++------- .../Structure/Control Structure/goto.adoc | 172 +++++----- Language/Structure/Control Structure/if.adoc | 212 ++++++------ .../Structure/Control Structure/return.adoc | 180 +++++----- .../Control Structure/switchCase.adoc | 202 ++++++------ .../Structure/Control Structure/while.adoc | 154 ++++----- .../Further Syntax/blockComment.adoc | 162 ++++----- Language/Structure/Further Syntax/define.adoc | 190 +++++------ .../Structure/Further Syntax/include.adoc | 170 +++++----- .../Structure/Further Syntax/semicolon.adoc | 128 ++++---- .../Further Syntax/singleLineComment.adoc | 140 ++++---- .../Pointer Access Operators/dereference.adoc | 142 ++++---- .../Pointer Access Operators/reference.adoc | 144 ++++---- Language/Structure/Sketch/loop.adoc | 138 ++++---- Language/Structure/Sketch/setup.adoc | 120 +++---- Language/Variables/Constants/constants.adoc | 262 +++++++-------- .../Constants/floatingPointConstants.adoc | 160 ++++----- .../Variables/Constants/integerConstants.adoc | 286 ++++++++-------- .../Data Types/String/Functions/c_str.adoc | 114 +++---- .../Data Types/String/Functions/charAt.adoc | 116 +++---- .../String/Functions/compareTo.adoc | 122 +++---- .../Data Types/String/Functions/concat.adoc | 118 +++---- .../Data Types/String/Functions/endsWith.adoc | 118 +++---- .../Data Types/String/Functions/equals.adoc | 116 +++---- .../String/Functions/equalsIgnoreCase.adoc | 118 +++---- .../Data Types/String/Functions/getBytes.adoc | 118 +++---- .../Data Types/String/Functions/indexOf.adoc | 122 +++---- .../String/Functions/lastIndexOf.adoc | 120 +++---- .../Data Types/String/Functions/length.adoc | 114 +++---- .../Data Types/String/Functions/remove.adoc | 146 ++++----- .../Data Types/String/Functions/replace.adoc | 118 +++---- .../Data Types/String/Functions/reserve.adoc | 176 +++++----- .../String/Functions/setCharAt.adoc | 118 +++---- .../String/Functions/startsWith.adoc | 116 +++---- .../String/Functions/substring.adoc | 120 +++---- .../String/Functions/toCharArray.adoc | 118 +++---- .../Data Types/String/Functions/toDouble.adoc | 114 +++---- .../Data Types/String/Functions/toFloat.adoc | 114 +++---- .../Data Types/String/Functions/toInt.adoc | 114 +++---- .../String/Functions/toLowerCase.adoc | 114 +++---- .../String/Functions/toUpperCase.adoc | 112 +++---- .../Data Types/String/Functions/trim.adoc | 114 +++---- .../Data Types/String/Operators/append.adoc | 118 +++---- .../String/Operators/comparison.adoc | 114 +++---- .../String/Operators/concatenation.adoc | 122 +++---- .../String/Operators/differentFrom.adoc | 122 +++---- .../String/Operators/elementAccess.adoc | 122 +++---- .../String/Operators/greaterThan.adoc | 124 +++---- .../Operators/greaterThanOrEqualTo.adoc | 116 +++---- .../Data Types/String/Operators/lessThan.adoc | 116 +++---- .../String/Operators/lessThanOrEqualTo.adoc | 126 +++---- .../Variables/Data Types/stringObject.adoc | 310 +++++++++--------- 81 files changed, 6117 insertions(+), 6117 deletions(-) diff --git a/Language/Functions/Characters/isUpperCase.adoc b/Language/Functions/Characters/isUpperCase.adoc index d03d3bacd..691271f4f 100644 --- a/Language/Functions/Characters/isUpperCase.adoc +++ b/Language/Functions/Characters/isUpperCase.adoc @@ -1,74 +1,74 @@ ---- -title: "isUpperCase()" -categories: [ "Functions" ] -subCategories: [ "Characters" ] ---- - -= isUpperCase(thisChar) - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Analyse if a char is upper case (that is, a letter in upper case). Returns true if thisChar is upper case. -[%hardbreaks] - - -[float] -=== Syntax -`isUpperCase(thisChar)` - - -[float] -=== Parameters -`thisChar`: variable. Allowed data types: `char`. - - -[float] -=== Returns -`true`: if thisChar is upper case. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -if (isUpperCase(myChar)) { // tests if myChar is an upper case letter - Serial.println("The character is upper case"); -} -else { - Serial.println("The character is not upper case"); -} ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../../variables/data-types/char[char] -* #LANGUAGE# link:../../../structure/control-structure/if[if (conditional operators)] -* #LANGUAGE# link:../../../structure/control-structure/while[while (conditional operators)] -* #LANGUAGE# link:../../communication/serial/read[read()] - --- -// SEE ALSO SECTION ENDS +--- +title: "isUpperCase()" +categories: [ "Functions" ] +subCategories: [ "Characters" ] +--- + += isUpperCase(thisChar) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Analyse if a char is upper case (that is, a letter in upper case). Returns true if thisChar is upper case. +[%hardbreaks] + + +[float] +=== Syntax +`isUpperCase(thisChar)` + + +[float] +=== Parameters +`thisChar`: variable. Allowed data types: `char`. + + +[float] +=== Returns +`true`: if thisChar is upper case. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +if (isUpperCase(myChar)) { // tests if myChar is an upper case letter + Serial.println("The character is upper case"); +} +else { + Serial.println("The character is not upper case"); +} +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../../variables/data-types/char[char] +* #LANGUAGE# link:../../../structure/control-structure/if[if (conditional operators)] +* #LANGUAGE# link:../../../structure/control-structure/while[while (conditional operators)] +* #LANGUAGE# link:../../communication/serial/read[read()] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Arithmetic Operators/addition.adoc b/Language/Structure/Arithmetic Operators/addition.adoc index e1c3877e0..ac1573e9b 100644 --- a/Language/Structure/Arithmetic Operators/addition.adoc +++ b/Language/Structure/Arithmetic Operators/addition.adoc @@ -1,89 +1,89 @@ ---- -title: "+" -title_expanded: "addition" -categories: [ "Structure" ] -subCategories: [ "Arithmetic Operators" ] ---- - - - - - -= + Addition - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Addition* is one of the four primary arithmetic operations. The operator `+` (plus) operates on two operands to produce the sum. -[%hardbreaks] - - -[float] -=== Syntax -`sum = operand1 + operand2;` - -[float] -=== Parameters -`sum`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`operand1`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`operand2`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 5; -int b = 10; -int c = 0; -c = a + b; // the variable 'c' gets a value of 15 after this statement is executed ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -1. The addition operation can overflow if the result is larger than that which can be stored in the data type (e.g. adding 1 to an integer with the value 32,767 gives -32,768). - -2. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. - -3. If the operands are of float / double data type and the variable that stores the sum is an integer, then only the integral part is stored and the fractional part of the number is lost. - -[source,arduino] ----- -float a = 5.5; -float b = 6.6; -int c = 0; -c = a + b; // the variable 'c' stores a value of 12 only as opposed to the expected sum of 12.1 ----- -[%hardbreaks] --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "+" +title_expanded: "addition" +categories: [ "Structure" ] +subCategories: [ "Arithmetic Operators" ] +--- + + + + + += + Addition + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Addition* is one of the four primary arithmetic operations. The operator `+` (plus) operates on two operands to produce the sum. +[%hardbreaks] + + +[float] +=== Syntax +`sum = operand1 + operand2;` + +[float] +=== Parameters +`sum`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`operand1`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`operand2`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 5; +int b = 10; +int c = 0; +c = a + b; // the variable 'c' gets a value of 15 after this statement is executed +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +1. The addition operation can overflow if the result is larger than that which can be stored in the data type (e.g. adding 1 to an integer with the value 32,767 gives -32,768). + +2. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. + +3. If the operands are of float / double data type and the variable that stores the sum is an integer, then only the integral part is stored and the fractional part of the number is lost. + +[source,arduino] +---- +float a = 5.5; +float b = 6.6; +int c = 0; +c = a + b; // the variable 'c' stores a value of 12 only as opposed to the expected sum of 12.1 +---- +[%hardbreaks] +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Arithmetic Operators/assignment.adoc b/Language/Structure/Arithmetic Operators/assignment.adoc index c6d3ab862..0d1b00141 100644 --- a/Language/Structure/Arithmetic Operators/assignment.adoc +++ b/Language/Structure/Arithmetic Operators/assignment.adoc @@ -1,70 +1,70 @@ ---- -title: "=" -title_expanded: "assignment operator" -categories: [ "Structure" ] -subCategories: [ "Arithmetic Operators" ] ---- - - - - - -= = Assignment (single equal sign) - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The single equal sign `=` in the C++ programming language is called the assignment operator. It has a different meaning than in algebra class where it indicated an equation or equality. The assignment operator tells the microcontroller to evaluate whatever value or expression is on the right side of the equal sign, and store it in the variable to the left of the equal sign. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - - - -[source,arduino] ----- -int sensVal; // declare an integer variable named sensVal -sensVal = analogRead(0); // store the (digitized) input voltage at analog pin 0 in SensVal ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -1. The variable on the left side of the assignment operator ( = sign ) needs to be able to hold the value stored in it. If it is not large enough to hold a value, the value stored in the variable will be incorrect. - -2. Don't confuse the assignment operator [ = ] (single equal sign) with the comparison operator [ == ] (double equal signs), which evaluates whether two expressions are equal. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - -// SEE ALSO SECTION STARTS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../control-structure/if[if (conditional operators)] -* #LANGUAGE# link:../../../variables/data-types/char[char] -* #LANGUAGE# link:../../../variables/data-types/int[int] -* #LANGUAGE# link:../../../variables/data-types/long[long] - --- -// SEE ALSO SECTION ENDS +--- +title: "=" +title_expanded: "assignment operator" +categories: [ "Structure" ] +subCategories: [ "Arithmetic Operators" ] +--- + + + + + += = Assignment (single equal sign) + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The single equal sign `=` in the C++ programming language is called the assignment operator. It has a different meaning than in algebra class where it indicated an equation or equality. The assignment operator tells the microcontroller to evaluate whatever value or expression is on the right side of the equal sign, and store it in the variable to the left of the equal sign. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + + + +[source,arduino] +---- +int sensVal; // declare an integer variable named sensVal +sensVal = analogRead(0); // store the (digitized) input voltage at analog pin 0 in SensVal +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +1. The variable on the left side of the assignment operator ( = sign ) needs to be able to hold the value stored in it. If it is not large enough to hold a value, the value stored in the variable will be incorrect. + +2. Don't confuse the assignment operator [ = ] (single equal sign) with the comparison operator [ == ] (double equal signs), which evaluates whether two expressions are equal. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + +// SEE ALSO SECTION STARTS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../control-structure/if[if (conditional operators)] +* #LANGUAGE# link:../../../variables/data-types/char[char] +* #LANGUAGE# link:../../../variables/data-types/int[int] +* #LANGUAGE# link:../../../variables/data-types/long[long] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Arithmetic Operators/division.adoc b/Language/Structure/Arithmetic Operators/division.adoc index c7c4c2518..7fd4fea5e 100644 --- a/Language/Structure/Arithmetic Operators/division.adoc +++ b/Language/Structure/Arithmetic Operators/division.adoc @@ -1,86 +1,86 @@ ---- -title: "/" -title_expanded: "division" -categories: [ "Structure" ] -subCategories: [ "Arithmetic Operators" ] ---- - - - - - -= / Division - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Division* is one of the four primary arithmetic operations. The operator `/` (slash) operates on two operands to produce the result. -[%hardbreaks] - - -[float] -=== Syntax -`result = numerator / denominator;` - - -[float] -=== Parameters -`result`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`numerator`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`denominator`: *non zero* variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 50; -int b = 10; -int c = 0; -c = a / b; // the variable 'c' gets a value of 5 after this statement is executed ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -1. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. - -2. If the operands are of float / double data type and the variable that stores the sum is an integer, then only the integral part is stored and the fractional part of the number is lost. - -[source,arduino] ----- -float a = 55.5; -float b = 6.6; -int c = 0; -c = a / b; // the variable 'c' stores a value of 8 only as opposed to the expected result of 8.409 ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - -// SEE ALSO SECTION STARTS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "/" +title_expanded: "division" +categories: [ "Structure" ] +subCategories: [ "Arithmetic Operators" ] +--- + + + + + += / Division + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Division* is one of the four primary arithmetic operations. The operator `/` (slash) operates on two operands to produce the result. +[%hardbreaks] + + +[float] +=== Syntax +`result = numerator / denominator;` + + +[float] +=== Parameters +`result`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`numerator`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`denominator`: *non zero* variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 50; +int b = 10; +int c = 0; +c = a / b; // the variable 'c' gets a value of 5 after this statement is executed +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +1. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. + +2. If the operands are of float / double data type and the variable that stores the sum is an integer, then only the integral part is stored and the fractional part of the number is lost. + +[source,arduino] +---- +float a = 55.5; +float b = 6.6; +int c = 0; +c = a / b; // the variable 'c' stores a value of 8 only as opposed to the expected result of 8.409 +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + +// SEE ALSO SECTION STARTS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Arithmetic Operators/multiplication.adoc b/Language/Structure/Arithmetic Operators/multiplication.adoc index 135022ce7..6cc778fbf 100644 --- a/Language/Structure/Arithmetic Operators/multiplication.adoc +++ b/Language/Structure/Arithmetic Operators/multiplication.adoc @@ -1,91 +1,91 @@ ---- -title: "*" -title_expanded: "multiplication" -categories: [ "Structure" ] -subCategories: [ "Arithmetic Operators" ] ---- - - - - - -= * Multiplication - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Multiplication* is one of the four primary arithmetic operations. The operator `*` (asterisk) operates on two operands to produce the product. -[%hardbreaks] - - -[float] -=== Syntax -`product = operand1 * operand2;` - - -[float] -=== Parameters -`product`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`operand1`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`operand2`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 5; -int b = 10; -int c = 0; -c = a * b; // the variable 'c' gets a value of 50 after this statement is executed ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -1. The multiplication operation can overflow if the result is bigger than that which can be stored in the data type. - -2. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. - -3. If the operands are of float / double data type and the variable that stores the product is an integer, then only the integral part is stored and the fractional part of the number is lost. - -[source,arduino] ----- -float a = 5.5; -float b = 6.6; -int c = 0; -c = a * b; // the variable 'c' stores a value of 36 only as opposed to the expected product of 36.3 ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION STARTS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "*" +title_expanded: "multiplication" +categories: [ "Structure" ] +subCategories: [ "Arithmetic Operators" ] +--- + + + + + += * Multiplication + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Multiplication* is one of the four primary arithmetic operations. The operator `*` (asterisk) operates on two operands to produce the product. +[%hardbreaks] + + +[float] +=== Syntax +`product = operand1 * operand2;` + + +[float] +=== Parameters +`product`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`operand1`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`operand2`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 5; +int b = 10; +int c = 0; +c = a * b; // the variable 'c' gets a value of 50 after this statement is executed +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +1. The multiplication operation can overflow if the result is bigger than that which can be stored in the data type. + +2. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. + +3. If the operands are of float / double data type and the variable that stores the product is an integer, then only the integral part is stored and the fractional part of the number is lost. + +[source,arduino] +---- +float a = 5.5; +float b = 6.6; +int c = 0; +c = a * b; // the variable 'c' stores a value of 36 only as opposed to the expected product of 36.3 +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION STARTS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Arithmetic Operators/subtraction.adoc b/Language/Structure/Arithmetic Operators/subtraction.adoc index 3a73fdac2..2644f5269 100644 --- a/Language/Structure/Arithmetic Operators/subtraction.adoc +++ b/Language/Structure/Arithmetic Operators/subtraction.adoc @@ -1,91 +1,91 @@ ---- -title: "-" -title_expanded: "subtraction" -categories: [ "Structure" ] -subCategories: [ "Arithmetic Operators" ] ---- - - - - - -= - Subtraction - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Subtraction* is one of the four primary arithmetic operations. The operator `-` (minus) operates on two operands to produce the difference of the second from the first. -[%hardbreaks] - - -[float] -=== Syntax -`difference = operand1 - operand2;` - - -[float] -=== Parameters -`difference`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`operand1`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`operand2`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 5; -int b = 10; -int c = 0; -c = a - b; // the variable 'c' gets a value of -5 after this statement is executed ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -1. The subtraction operation can overflow if the result is smaller than that which can be stored in the data type (e.g. subtracting 1 from an integer with the value -32,768 gives 32,767). - -2. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. - -3. If the operands are of float / double data type and the variable that stores the difference is an integer, then only the integral part is stored and the fractional part of the number is lost. - -[source,arduino] ----- -float a = 5.5; -float b = 6.6; -int c = 0; -c = a - b; // the variable 'c' stores a value of -1 only as opposed to the expected difference of -1.1 ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION STARTS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "-" +title_expanded: "subtraction" +categories: [ "Structure" ] +subCategories: [ "Arithmetic Operators" ] +--- + + + + + += - Subtraction + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Subtraction* is one of the four primary arithmetic operations. The operator `-` (minus) operates on two operands to produce the difference of the second from the first. +[%hardbreaks] + + +[float] +=== Syntax +`difference = operand1 - operand2;` + + +[float] +=== Parameters +`difference`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`operand1`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`operand2`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 5; +int b = 10; +int c = 0; +c = a - b; // the variable 'c' gets a value of -5 after this statement is executed +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +1. The subtraction operation can overflow if the result is smaller than that which can be stored in the data type (e.g. subtracting 1 from an integer with the value -32,768 gives 32,767). + +2. If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. + +3. If the operands are of float / double data type and the variable that stores the difference is an integer, then only the integral part is stored and the fractional part of the number is lost. + +[source,arduino] +---- +float a = 5.5; +float b = 6.6; +int c = 0; +c = a - b; // the variable 'c' stores a value of -1 only as opposed to the expected difference of -1.1 +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION STARTS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Bitwise Operators/bitshiftLeft.adoc b/Language/Structure/Bitwise Operators/bitshiftLeft.adoc index 5fc3c2098..5a4c97a5a 100644 --- a/Language/Structure/Bitwise Operators/bitshiftLeft.adoc +++ b/Language/Structure/Bitwise Operators/bitshiftLeft.adoc @@ -1,121 +1,121 @@ ---- -title: "<<" -title_expanded: bitshift left -categories: [ "Structure" ] -subCategories: [ "Bitwise Operators" ] ---- - - - - - -= << Bitshift Left - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The left shift operator `<<` causes the bits of the left operand to be shifted *left* by the number of positions specified by the right operand. -[%hardbreaks] - - -[float] -=== Syntax -`variable << number_of_bits;` - - -[float] -=== Parameters -`variable`: Allowed data types: `byte`, `int`, `long`. + -`number_of_bits`: a number that is < = 32. Allowed data types: `int`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 5; // binary: 0000000000000101 -int b = a << 3; // binary: 0000000000101000, or 40 in decimal ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -When you shift a value x by y bits (x << y), the leftmost y bits in x are lost, literally shifted out of existence: - -[source,arduino] ----- -int x = 5; // binary: 0000000000000101 -int y = 14; -int result = x << y; // binary: 0100000000000000 - the first 1 in 101 was discarded ----- - -If you are certain that none of the ones in a value are being shifted into oblivion, a simple way to think of the left-shift operator is that it multiplies the left operand by 2 raised to the right operand power. For example, to generate powers of 2, the following expressions can be employed: - -[source,arduino] ----- - Operation Result - --------- ------ - 1 << 0 1 - 1 << 1 2 - 1 << 2 4 - 1 << 3 8 - ... - 1 << 8 256 - 1 << 9 512 - 1 << 10 1024 - ... ----- - -The following example can be used to print out the value of a received byte to the serial monitor, using the left shift operator to move along the byte from bottom(LSB) to top (MSB), and print out its Binary value: - -[source,arduino] ----- -// Prints out Binary value (1 or 0) of byte -void printOut1(int c) { - for (int bits = 7; bits > -1; bits--) { - // Compare bits 7-0 in byte - if (c & (1 << bits)) { - Serial.print("1"); - } - else { - Serial.print("0"); - } - } -} ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -//SEE ALSO SECTION STARTS -[#see_also] --- - -[float] -=== See also - -[role="language"] - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] - --- -//SEE ALSO SECTION ENDS - +--- +title: "<<" +title_expanded: bitshift left +categories: [ "Structure" ] +subCategories: [ "Bitwise Operators" ] +--- + + + + + += << Bitshift Left + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The left shift operator `<<` causes the bits of the left operand to be shifted *left* by the number of positions specified by the right operand. +[%hardbreaks] + + +[float] +=== Syntax +`variable << number_of_bits;` + + +[float] +=== Parameters +`variable`: Allowed data types: `byte`, `int`, `long`. + +`number_of_bits`: a number that is < = 32. Allowed data types: `int`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 5; // binary: 0000000000000101 +int b = a << 3; // binary: 0000000000101000, or 40 in decimal +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you shift a value x by y bits (x << y), the leftmost y bits in x are lost, literally shifted out of existence: + +[source,arduino] +---- +int x = 5; // binary: 0000000000000101 +int y = 14; +int result = x << y; // binary: 0100000000000000 - the first 1 in 101 was discarded +---- + +If you are certain that none of the ones in a value are being shifted into oblivion, a simple way to think of the left-shift operator is that it multiplies the left operand by 2 raised to the right operand power. For example, to generate powers of 2, the following expressions can be employed: + +[source,arduino] +---- + Operation Result + --------- ------ + 1 << 0 1 + 1 << 1 2 + 1 << 2 4 + 1 << 3 8 + ... + 1 << 8 256 + 1 << 9 512 + 1 << 10 1024 + ... +---- + +The following example can be used to print out the value of a received byte to the serial monitor, using the left shift operator to move along the byte from bottom(LSB) to top (MSB), and print out its Binary value: + +[source,arduino] +---- +// Prints out Binary value (1 or 0) of byte +void printOut1(int c) { + for (int bits = 7; bits > -1; bits--) { + // Compare bits 7-0 in byte + if (c & (1 << bits)) { + Serial.print("1"); + } + else { + Serial.print("0"); + } + } +} +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +//SEE ALSO SECTION STARTS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] + +-- +//SEE ALSO SECTION ENDS + diff --git a/Language/Structure/Bitwise Operators/bitshiftRight.adoc b/Language/Structure/Bitwise Operators/bitshiftRight.adoc index 2d21f89c6..f2f98b840 100644 --- a/Language/Structure/Bitwise Operators/bitshiftRight.adoc +++ b/Language/Structure/Bitwise Operators/bitshiftRight.adoc @@ -1,97 +1,97 @@ ---- -title: ">>" -title_expanded: bitshift right -categories: [ "Structure" ] -subCategories: [ "Bitwise Operators" ] ---- - - - - - -= >> Bitshift Right - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The right shift operator `>>` causes the bits of the left operand to be shifted *right* by the number of positions specified by the right operand. -[%hardbreaks] - - -[float] -=== Syntax -`variable >> number_of_bits;` - - -[float] -=== Parameters -`variable`: Allowed data types: `byte`, `int`, `long`. + -`number_of_bits`: a number that is < = 32. Allowed data types: `int`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 40; // binary: 0000000000101000 -int b = a >> 3; // binary: 0000000000000101, or 5 in decimal ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -When you shift x right by y bits (x >> y), and the highest bit in x is a 1, the behavior depends on the exact data type of x. If x is of type int, the highest bit is the sign bit, determining whether x is negative or not, as we have discussed above. In that case, the sign bit is copied into lower bits, for esoteric historical reasons: - -[source,arduino] ----- -int x = -16; // binary: 1111111111110000 -int y = 3; -int result = x >> y; // binary: 1111111111111110 ----- -This behavior, called sign extension, is often not the behavior you want. Instead, you may wish zeros to be shifted in from the left. It turns out that the right shift rules are different for unsigned int expressions, so you can use a typecast to suppress ones being copied from the left: - -[source,arduino] ----- -int x = -16; // binary: 1111111111110000 -int y = 3; -int result = (unsigned int)x >> y; // binary: 0001111111111110 ----- -If you are careful to avoid sign extension, you can use the right-shift operator `>>` as a way to divide by powers of 2. For example: - -[source,arduino] ----- -int x = 1000; -int y = x >> 3; // integer division of 1000 by 8, causing y = 125. ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] - -[role="example"] -* #EXAMPLE# http://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] - --- -// SEE ALSO SECTION ENDS +--- +title: ">>" +title_expanded: bitshift right +categories: [ "Structure" ] +subCategories: [ "Bitwise Operators" ] +--- + + + + + += >> Bitshift Right + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The right shift operator `>>` causes the bits of the left operand to be shifted *right* by the number of positions specified by the right operand. +[%hardbreaks] + + +[float] +=== Syntax +`variable >> number_of_bits;` + + +[float] +=== Parameters +`variable`: Allowed data types: `byte`, `int`, `long`. + +`number_of_bits`: a number that is < = 32. Allowed data types: `int`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 40; // binary: 0000000000101000 +int b = a >> 3; // binary: 0000000000000101, or 5 in decimal +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When you shift x right by y bits (x >> y), and the highest bit in x is a 1, the behavior depends on the exact data type of x. If x is of type int, the highest bit is the sign bit, determining whether x is negative or not, as we have discussed above. In that case, the sign bit is copied into lower bits, for esoteric historical reasons: + +[source,arduino] +---- +int x = -16; // binary: 1111111111110000 +int y = 3; +int result = x >> y; // binary: 1111111111111110 +---- +This behavior, called sign extension, is often not the behavior you want. Instead, you may wish zeros to be shifted in from the left. It turns out that the right shift rules are different for unsigned int expressions, so you can use a typecast to suppress ones being copied from the left: + +[source,arduino] +---- +int x = -16; // binary: 1111111111110000 +int y = 3; +int result = (unsigned int)x >> y; // binary: 0001111111111110 +---- +If you are careful to avoid sign extension, you can use the right-shift operator `>>` as a way to divide by powers of 2. For example: + +[source,arduino] +---- +int x = 1000; +int y = x >> 3; // integer division of 1000 by 8, causing y = 125. +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +[role="example"] +* #EXAMPLE# http://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Bitwise Operators/bitwiseAnd.adoc b/Language/Structure/Bitwise Operators/bitwiseAnd.adoc index 018779152..986a37fcc 100644 --- a/Language/Structure/Bitwise Operators/bitwiseAnd.adoc +++ b/Language/Structure/Bitwise Operators/bitwiseAnd.adoc @@ -1,83 +1,83 @@ ---- -title: "&" -title_expanded: bitwise and -categories: [ "Structure" ] -subCategories: [ "Bitwise Operators" ] ---- - - - - - -= & Bitwise AND - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The bitwise AND operator in C++ is a single ampersand `&`, used between two other integer expressions. Bitwise AND operates on each bit position of the surrounding expressions independently, according to this rule: if both input bits are 1, the resulting output is 1, otherwise the output is 0. -[%hardbreaks] - -Another way of expressing this is: - - 0 0 1 1 operand1 - 0 1 0 1 operand2 - ---------- - 0 0 0 1 (operand1 & operand2) - returned result -[%hardbreaks] - -In Arduino, the type int is a 16-bit value, so using & between two int expressions causes 16 simultaneous AND operations to occur. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -In a code fragment like: - -[source,arduino] ----- -int a = 92; // in binary: 0000000001011100 -int b = 101; // in binary: 0000000001100101 -int c = a & b; // result: 0000000001000100, or 68 in decimal. ----- -Each of the 16 bits in a and b are processed by using the bitwise AND, and all 16 resulting bits are stored in c, resulting in the value 01000100 in binary, which is 68 in decimal. -[%hardbreaks] - -One of the most common uses of bitwise AND is to select a particular bit (or bits) from an integer value, often called masking. See below for an example (AVR architecture specific). - -[source,arduino] ----- -PORTD = PORTD & B00000011; // clear out bits 2 - 7, leave pins PD0 and PD1 untouched (xx & 11 == xx) ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - - -[role="language"] -* #LANGUAGE# link:../../boolean-operators/logicaland[&& Logical AND] - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] - --- -// SEE ALSO SECTION ENDS +--- +title: "&" +title_expanded: bitwise and +categories: [ "Structure" ] +subCategories: [ "Bitwise Operators" ] +--- + + + + + += & Bitwise AND + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The bitwise AND operator in C++ is a single ampersand `&`, used between two other integer expressions. Bitwise AND operates on each bit position of the surrounding expressions independently, according to this rule: if both input bits are 1, the resulting output is 1, otherwise the output is 0. +[%hardbreaks] + +Another way of expressing this is: + + 0 0 1 1 operand1 + 0 1 0 1 operand2 + ---------- + 0 0 0 1 (operand1 & operand2) - returned result +[%hardbreaks] + +In Arduino, the type int is a 16-bit value, so using & between two int expressions causes 16 simultaneous AND operations to occur. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +In a code fragment like: + +[source,arduino] +---- +int a = 92; // in binary: 0000000001011100 +int b = 101; // in binary: 0000000001100101 +int c = a & b; // result: 0000000001000100, or 68 in decimal. +---- +Each of the 16 bits in a and b are processed by using the bitwise AND, and all 16 resulting bits are stored in c, resulting in the value 01000100 in binary, which is 68 in decimal. +[%hardbreaks] + +One of the most common uses of bitwise AND is to select a particular bit (or bits) from an integer value, often called masking. See below for an example (AVR architecture specific). + +[source,arduino] +---- +PORTD = PORTD & B00000011; // clear out bits 2 - 7, leave pins PD0 and PD1 untouched (xx & 11 == xx) +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + + +[role="language"] +* #LANGUAGE# link:../../boolean-operators/logicaland[&& Logical AND] + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Bitwise Operators/bitwiseNot.adoc b/Language/Structure/Bitwise Operators/bitwiseNot.adoc index 446e507e8..7a35ec1a2 100644 --- a/Language/Structure/Bitwise Operators/bitwiseNot.adoc +++ b/Language/Structure/Bitwise Operators/bitwiseNot.adoc @@ -1,76 +1,76 @@ ---- -title: "~" -title_expanded: bitwise not -categories: [ "Structure" ] -subCategories: [ "Bitwise Operators" ] ---- - - - - - -= ~ Bitwise NOT - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The bitwise NOT operator in C++ is the tilde character `~`. Unlike & and |, the bitwise NOT operator is applied to a single operand to its right. Bitwise NOT changes each bit to its opposite: 0 becomes 1, and 1 becomes 0. -[%hardbreaks] - -In other words: - - 0 1 operand1 - ----- - 1 0 ~operand1 -[%hardbreaks] --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 103; // binary: 0000000001100111 -int b = ~a; // binary: 1111111110011000 = -104 ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -You might be surprised to see a negative number like -104 as the result of this operation. This is because the highest bit in an int variable is the so-called sign bit. If the highest bit is 1, the number is interpreted as negative. This encoding of positive and negative numbers is referred to as two's complement. For more information, see the Wikipedia article on http://en.wikipedia.org/wiki/Twos_complement[two's complement^]. - -As an aside, it is interesting to note that for any integer x, ~x is the same as -x - 1. - -At times, the sign bit in a signed integer expression can cause some unwanted surprises. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] - --- -//SEE ALSO SECTION ENDS +--- +title: "~" +title_expanded: bitwise not +categories: [ "Structure" ] +subCategories: [ "Bitwise Operators" ] +--- + + + + + += ~ Bitwise NOT + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The bitwise NOT operator in C++ is the tilde character `~`. Unlike & and |, the bitwise NOT operator is applied to a single operand to its right. Bitwise NOT changes each bit to its opposite: 0 becomes 1, and 1 becomes 0. +[%hardbreaks] + +In other words: + + 0 1 operand1 + ----- + 1 0 ~operand1 +[%hardbreaks] +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 103; // binary: 0000000001100111 +int b = ~a; // binary: 1111111110011000 = -104 +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +You might be surprised to see a negative number like -104 as the result of this operation. This is because the highest bit in an int variable is the so-called sign bit. If the highest bit is 1, the number is interpreted as negative. This encoding of positive and negative numbers is referred to as two's complement. For more information, see the Wikipedia article on http://en.wikipedia.org/wiki/Twos_complement[two's complement^]. + +As an aside, it is interesting to note that for any integer x, ~x is the same as -x - 1. + +At times, the sign bit in a signed integer expression can cause some unwanted surprises. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] + +-- +//SEE ALSO SECTION ENDS diff --git a/Language/Structure/Bitwise Operators/bitwiseOr.adoc b/Language/Structure/Bitwise Operators/bitwiseOr.adoc index 3b2d84c70..14d894b8a 100644 --- a/Language/Structure/Bitwise Operators/bitwiseOr.adoc +++ b/Language/Structure/Bitwise Operators/bitwiseOr.adoc @@ -1,81 +1,81 @@ ---- -title: "|" -title_expanded: bitwise or -categories: [ "Structure" ] -subCategories: [ "Bitwise Operators" ] ---- - - - - - -= | Bitwise OR - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The bitwise OR operator in C++ is the vertical bar symbol, |. Like the & operator, | operates independently each bit in its two surrounding integer expressions, but what it does is different (of course). The bitwise OR of two bits is 1 if either or both of the input bits is 1, otherwise it is 0. -[%hardbreaks] - -In other words: - - 0 0 1 1 operand1 - 0 1 0 1 operand2 - ---------- - 0 1 1 1 (operand1 | operand2) - returned result -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 92; // in binary: 0000000001011100 -int b = 101; // in binary: 0000000001100101 -int c = a | b; // result: 0000000001111101, or 125 in decimal. ----- -[%hardbreaks] - -One of the most common uses of the Bitwise OR is to set multiple bits in a bit-packed number. - -[source,arduino] ----- -// Note: This code is AVR architecture specific -// set direction bits for pins 2 to 7, leave PD0 and PD1 untouched (xx | 00 == xx) -// same as pinMode(pin, OUTPUT) for pins 2 to 7 on Uno or Nano -DDRD = DDRD | B11111100; ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - - -[role="language"] -* #LANGUAGE# link:../../boolean-operators/logicalor[|| Logical OR] - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] - --- -// SEE ALSO SECTION ENDS +--- +title: "|" +title_expanded: bitwise or +categories: [ "Structure" ] +subCategories: [ "Bitwise Operators" ] +--- + + + + + += | Bitwise OR + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The bitwise OR operator in C++ is the vertical bar symbol, |. Like the & operator, | operates independently each bit in its two surrounding integer expressions, but what it does is different (of course). The bitwise OR of two bits is 1 if either or both of the input bits is 1, otherwise it is 0. +[%hardbreaks] + +In other words: + + 0 0 1 1 operand1 + 0 1 0 1 operand2 + ---------- + 0 1 1 1 (operand1 | operand2) - returned result +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 92; // in binary: 0000000001011100 +int b = 101; // in binary: 0000000001100101 +int c = a | b; // result: 0000000001111101, or 125 in decimal. +---- +[%hardbreaks] + +One of the most common uses of the Bitwise OR is to set multiple bits in a bit-packed number. + +[source,arduino] +---- +// Note: This code is AVR architecture specific +// set direction bits for pins 2 to 7, leave PD0 and PD1 untouched (xx | 00 == xx) +// same as pinMode(pin, OUTPUT) for pins 2 to 7 on Uno or Nano +DDRD = DDRD | B11111100; +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + + +[role="language"] +* #LANGUAGE# link:../../boolean-operators/logicalor[|| Logical OR] + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Bitwise Operators/bitwiseXor.adoc b/Language/Structure/Bitwise Operators/bitwiseXor.adoc index affe474bd..d4677dbf9 100644 --- a/Language/Structure/Bitwise Operators/bitwiseXor.adoc +++ b/Language/Structure/Bitwise Operators/bitwiseXor.adoc @@ -1,85 +1,85 @@ ---- -title: "^" -title_expanded: bitwise xor -categories: [ "Structure" ] -subCategories: [ "Bitwise Operators" ] ---- - - - - - -= ^ Bitwise XOR - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -There is a somewhat unusual operator in C++ called bitwise EXCLUSIVE OR, also known as bitwise XOR. (In English this is usually pronounced "eks-or".) The bitwise XOR operator is written using the caret symbol `^`. A bitwise XOR operation results in a 1 only if the input bits are different, else it results in a 0. -[%hardbreaks] - -Precisely, - - 0 0 1 1 operand1 - 0 1 0 1 operand2 - ---------- - 0 1 1 0 (operand1 ^ operand2) - returned result -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int x = 12; // binary: 1100 -int y = 10; // binary: 1010 -int z = x ^ y; // binary: 0110, or decimal 6 ----- -[%hardbreaks] - -The ^ operator is often used to toggle (i.e. change from 0 to 1, or 1 to 0) some of the bits in an integer expression. In a bitwise XOR operation if there is a 1 in the mask bit, that bit is inverted; if there is a 0, the bit is not inverted and stays the same. - -[source,arduino] ----- -// Note: This code uses registers specific to AVR microcontrollers (Uno, Nano, Leonardo, Mega, etc.) -// it will not compile for other architectures -void setup() { - DDRB = DDRB | B00100000; // set PB5 (pin 13 on Uno/Nano, pin 9 on Leonardo/Micro, pin 11 on Mega) as OUTPUT - Serial.begin(9600); -} - -void loop() { - PORTB = PORTB ^ B00100000; // invert PB5, leave others untouched - delay(100); -} ----- - - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] - --- -// SEE ALSO SECTION ENDS +--- +title: "^" +title_expanded: bitwise xor +categories: [ "Structure" ] +subCategories: [ "Bitwise Operators" ] +--- + + + + + += ^ Bitwise XOR + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +There is a somewhat unusual operator in C++ called bitwise EXCLUSIVE OR, also known as bitwise XOR. (In English this is usually pronounced "eks-or".) The bitwise XOR operator is written using the caret symbol `^`. A bitwise XOR operation results in a 1 only if the input bits are different, else it results in a 0. +[%hardbreaks] + +Precisely, + + 0 0 1 1 operand1 + 0 1 0 1 operand2 + ---------- + 0 1 1 0 (operand1 ^ operand2) - returned result +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int x = 12; // binary: 1100 +int y = 10; // binary: 1010 +int z = x ^ y; // binary: 0110, or decimal 6 +---- +[%hardbreaks] + +The ^ operator is often used to toggle (i.e. change from 0 to 1, or 1 to 0) some of the bits in an integer expression. In a bitwise XOR operation if there is a 1 in the mask bit, that bit is inverted; if there is a 0, the bit is not inverted and stays the same. + +[source,arduino] +---- +// Note: This code uses registers specific to AVR microcontrollers (Uno, Nano, Leonardo, Mega, etc.) +// it will not compile for other architectures +void setup() { + DDRB = DDRB | B00100000; // set PB5 (pin 13 on Uno/Nano, pin 9 on Leonardo/Micro, pin 11 on Mega) as OUTPUT + Serial.begin(9600); +} + +void loop() { + PORTB = PORTB ^ B00100000; // invert PB5, leave others untouched + delay(100); +} +---- + + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/playground/Code/BitMath[BitMath Tutorial^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Boolean Operators/logicalAnd.adoc b/Language/Structure/Boolean Operators/logicalAnd.adoc index 69bd81114..b46a749cf 100644 --- a/Language/Structure/Boolean Operators/logicalAnd.adoc +++ b/Language/Structure/Boolean Operators/logicalAnd.adoc @@ -1,64 +1,64 @@ ---- -title: "&&" -title_expanded: logical and -categories: [ "Structure" ] -subCategories: [ "Boolean Operators" ] ---- - - - - - -= && Logical AND - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Logical AND* results in `true` *only* if both operands are `true`. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -This operator can be used inside the condition of an link:../../control-structure/if[if] statement. - -[source,arduino] ----- -if (digitalRead(2) == HIGH && digitalRead(3) == HIGH) { // if BOTH the switches read HIGH - // statements -} ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Make sure you don't mistake the boolean AND operator, && (double ampersand) for the bitwise AND operator & (single ampersand). They are entirely different beasts. - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../bitwise-operators/bitwiseand[& (Bitwise AND)] - --- -// SEE ALSO SECTION ENDS +--- +title: "&&" +title_expanded: logical and +categories: [ "Structure" ] +subCategories: [ "Boolean Operators" ] +--- + + + + + += && Logical AND + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Logical AND* results in `true` *only* if both operands are `true`. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +This operator can be used inside the condition of an link:../../control-structure/if[if] statement. + +[source,arduino] +---- +if (digitalRead(2) == HIGH && digitalRead(3) == HIGH) { // if BOTH the switches read HIGH + // statements +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Make sure you don't mistake the boolean AND operator, && (double ampersand) for the bitwise AND operator & (single ampersand). They are entirely different beasts. + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../bitwise-operators/bitwiseand[& (Bitwise AND)] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Boolean Operators/logicalNot.adoc b/Language/Structure/Boolean Operators/logicalNot.adoc index b4c1a7a8b..7fa92071e 100644 --- a/Language/Structure/Boolean Operators/logicalNot.adoc +++ b/Language/Structure/Boolean Operators/logicalNot.adoc @@ -1,72 +1,72 @@ ---- -title: "!" -title_expanded: logical not -categories: [ "Structure" ] -subCategories: [ "Boolean Operators" ] ---- - - - - - -= ! Logical NOT - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Logical NOT* results in a `true` if the operand is `false` and vice versa. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -This operator can be used inside the condition of an link:../../control-structure/if/[if] statement. - -[source,arduino] ----- -if (!x) { // if x is not true - // statements -} ----- - -It can be used to invert the boolean value. -[source,arduino] ----- -x = !y; // the inverted value of y is stored in x ----- - - -[%hardbreaks] - -[float] -=== Notes and Warnings -The bitwise not ~ (tilde) looks much different than the boolean not ! (exclamation point or "bang" as the programmers say) but you still have to be sure which one you want where. - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../bitwise-operators/bitwisenot[~ Bitwise NOT] - --- -// SEE ALSO SECTION ENDS +--- +title: "!" +title_expanded: logical not +categories: [ "Structure" ] +subCategories: [ "Boolean Operators" ] +--- + + + + + += ! Logical NOT + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Logical NOT* results in a `true` if the operand is `false` and vice versa. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +This operator can be used inside the condition of an link:../../control-structure/if/[if] statement. + +[source,arduino] +---- +if (!x) { // if x is not true + // statements +} +---- + +It can be used to invert the boolean value. +[source,arduino] +---- +x = !y; // the inverted value of y is stored in x +---- + + +[%hardbreaks] + +[float] +=== Notes and Warnings +The bitwise not ~ (tilde) looks much different than the boolean not ! (exclamation point or "bang" as the programmers say) but you still have to be sure which one you want where. + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../bitwise-operators/bitwisenot[~ Bitwise NOT] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Boolean Operators/logicalOr.adoc b/Language/Structure/Boolean Operators/logicalOr.adoc index 4b2fc8727..5032e7aae 100644 --- a/Language/Structure/Boolean Operators/logicalOr.adoc +++ b/Language/Structure/Boolean Operators/logicalOr.adoc @@ -1,66 +1,66 @@ ---- -title: "||" -title_expanded: logical or -categories: [ "Structure" ] -subCategories: [ "Boolean Operators" ] ---- - - - - - -= || Logical OR - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Logical OR* results in a `true` if either of the two operands is `true`. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -This operator can be used inside the condition of an link:../../control-structure/if[if] statement. - -[source,arduino] ----- -if (x > 0 || y > 0) { // if either x or y is greater than zero - // statements -} ----- - -[%hardbreaks] - -[float] -=== Notes and Warnings -Do not confuse the boolean || (double pipe) operator with the bitwise OR operator | (single pipe). -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../bitwise-operators/bitwiseor[| Bitwise OR] - --- -// SEE ALSO SECTION ENDS +--- +title: "||" +title_expanded: logical or +categories: [ "Structure" ] +subCategories: [ "Boolean Operators" ] +--- + + + + + += || Logical OR + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Logical OR* results in a `true` if either of the two operands is `true`. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +This operator can be used inside the condition of an link:../../control-structure/if[if] statement. + +[source,arduino] +---- +if (x > 0 || y > 0) { // if either x or y is greater than zero + // statements +} +---- + +[%hardbreaks] + +[float] +=== Notes and Warnings +Do not confuse the boolean || (double pipe) operator with the bitwise OR operator | (single pipe). +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../bitwise-operators/bitwiseor[| Bitwise OR] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundAddition.adoc b/Language/Structure/Compound Operators/compoundAddition.adoc index 97aad457a..e5be622f6 100644 --- a/Language/Structure/Compound Operators/compoundAddition.adoc +++ b/Language/Structure/Compound Operators/compoundAddition.adoc @@ -1,68 +1,68 @@ ---- -title: "+=" -title_expanded: compound addition -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= += Compound Addition - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -This is a convenient shorthand to perform addition on a variable with another constant or variable. -[%hardbreaks] - - -[float] -=== Syntax -`x += y; // equivalent to the expression x = x + y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`y`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -x = 2; -x += 4; // x now contains 6 ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../arithmetic-operators/addition[Normal Addition] - --- -// SEE ALSO SECTION ENDS +--- +title: "+=" +title_expanded: compound addition +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += += Compound Addition + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +This is a convenient shorthand to perform addition on a variable with another constant or variable. +[%hardbreaks] + + +[float] +=== Syntax +`x += y; // equivalent to the expression x = x + y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`y`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +x = 2; +x += 4; // x now contains 6 +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../arithmetic-operators/addition[Normal Addition] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundBitwiseAnd.adoc b/Language/Structure/Compound Operators/compoundBitwiseAnd.adoc index c37af3726..2e33d7317 100644 --- a/Language/Structure/Compound Operators/compoundBitwiseAnd.adoc +++ b/Language/Structure/Compound Operators/compoundBitwiseAnd.adoc @@ -1,119 +1,119 @@ ---- -title: "&=" -title_expanded: compound bitwise and -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= &= Compound Bitwise AND - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The compound bitwise AND operator `&=` is often used with a variable and a constant to force particular bits in a variable to the LOW state (to 0). This is often referred to in programming guides as "clearing" or "resetting" bits. -[%hardbreaks] - -A review of the Bitwise AND `&` operator: - - 0 0 1 1 operand1 - 0 1 0 1 operand2 - ---------- - 0 0 0 1 (operand1 & operand2) - returned result -[%hardbreaks] - -[float] -=== Syntax -`x &= y; // equivalent to x = x & y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `char`, `int`, `long`. + -`y`: variable or constant. Allowed data types: `char`, `int`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -Bits that are "bitwise ANDed" with 0 are cleared to 0 so, if myByte is a byte variable, - -[source,arduino] ----- -myByte & B00000000 = 0; ----- - -Bits that are "bitwise ANDed" with 1 are unchanged so, - -[source,arduino] ----- -myByte & B11111111 = myByte; ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero (hmmm something philosophical there?) - -Consequently - to clear (set to zero) bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise AND operator (&=) with the constant B11111100 - - 1 0 1 0 1 0 1 0 variable - 1 1 1 1 1 1 0 0 mask - ---------------------- - 1 0 1 0 1 0 0 0 - - bits unchanged - bits cleared - -Here is the same representation with the variable's bits replaced with the symbol x - - x x x x x x x x variable - 1 1 1 1 1 1 0 0 mask - ---------------------- - x x x x x x 0 0 - - bits unchanged - bits cleared - -So if: - -[source,arduino] ----- -myByte = B10101010; -myByte &= B11111100; // results in B10101000 ----- - -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../bitwise-operators/bitwiseand[& Bitwise AND] - --- -// SEE ALSO SECTION ENDS +--- +title: "&=" +title_expanded: compound bitwise and +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += &= Compound Bitwise AND + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The compound bitwise AND operator `&=` is often used with a variable and a constant to force particular bits in a variable to the LOW state (to 0). This is often referred to in programming guides as "clearing" or "resetting" bits. +[%hardbreaks] + +A review of the Bitwise AND `&` operator: + + 0 0 1 1 operand1 + 0 1 0 1 operand2 + ---------- + 0 0 0 1 (operand1 & operand2) - returned result +[%hardbreaks] + +[float] +=== Syntax +`x &= y; // equivalent to x = x & y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `char`, `int`, `long`. + +`y`: variable or constant. Allowed data types: `char`, `int`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +Bits that are "bitwise ANDed" with 0 are cleared to 0 so, if myByte is a byte variable, + +[source,arduino] +---- +myByte & B00000000 = 0; +---- + +Bits that are "bitwise ANDed" with 1 are unchanged so, + +[source,arduino] +---- +myByte & B11111111 = myByte; +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero (hmmm something philosophical there?) + +Consequently - to clear (set to zero) bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise AND operator (&=) with the constant B11111100 + + 1 0 1 0 1 0 1 0 variable + 1 1 1 1 1 1 0 0 mask + ---------------------- + 1 0 1 0 1 0 0 0 + + bits unchanged + bits cleared + +Here is the same representation with the variable's bits replaced with the symbol x + + x x x x x x x x variable + 1 1 1 1 1 1 0 0 mask + ---------------------- + x x x x x x 0 0 + + bits unchanged + bits cleared + +So if: + +[source,arduino] +---- +myByte = B10101010; +myByte &= B11111100; // results in B10101000 +---- + +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../bitwise-operators/bitwiseand[& Bitwise AND] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundBitwiseOr.adoc b/Language/Structure/Compound Operators/compoundBitwiseOr.adoc index c2b4bafd5..815d98771 100644 --- a/Language/Structure/Compound Operators/compoundBitwiseOr.adoc +++ b/Language/Structure/Compound Operators/compoundBitwiseOr.adoc @@ -1,112 +1,112 @@ ---- -title: "|=" -title_expanded: compound bitwise or -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - -= |= Compound Bitwise OR - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The compound bitwise OR operator `|=` is often used with a variable and a constant to "set" (set to 1) particular bits in a variable. -[%hardbreaks] - -A review of the Bitwise OR `|` operator: - - 0 0 1 1 operand1 - 0 1 0 1 operand2 - ---------- - 0 1 1 1 (operand1 | operand2) - returned result -[%hardbreaks] - -[float] -=== Syntax -`x |= y; // equivalent to x = x | y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `char`, `int`, `long`. + -`y`: variable or constant. Allowed data types: `char`, `int`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -Bits that are "bitwise ORed" with 0 are unchanged, so if myByte is a byte variable, -[source,arduino] ----- -myByte | B00000000 = myByte; ----- - -Bits that are "bitwise ORed" with 1 are set to 1 so: -[source,arduino] ----- -myByte | B11111111 = B11111111; ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero. -[%hardbreaks] - -Consequently - to set bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise OR operator (|=) with the constant B00000011 - - 1 0 1 0 1 0 1 0 variable - 0 0 0 0 0 0 1 1 mask - ---------------------- - 1 0 1 0 1 0 1 1 - - bits unchanged - bits set - - -Here is the same representation with the variables bits replaced with the symbol x - - x x x x x x x x variable - 0 0 0 0 0 0 1 1 mask - ---------------------- - x x x x x x 1 1 - - bits unchanged - bits set - -So if: -[source,arduino] ----- -myByte = B10101010; -myByte |= B00000011 == B10101011; ----- - --- -// HOW TO USE SECTION ENDS - - - - -//SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../bitwise-operators/bitwiseor[| Bitwise OR] - --- -// SEE ALSO SECTION ENDS +--- +title: "|=" +title_expanded: compound bitwise or +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + += |= Compound Bitwise OR + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The compound bitwise OR operator `|=` is often used with a variable and a constant to "set" (set to 1) particular bits in a variable. +[%hardbreaks] + +A review of the Bitwise OR `|` operator: + + 0 0 1 1 operand1 + 0 1 0 1 operand2 + ---------- + 0 1 1 1 (operand1 | operand2) - returned result +[%hardbreaks] + +[float] +=== Syntax +`x |= y; // equivalent to x = x | y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `char`, `int`, `long`. + +`y`: variable or constant. Allowed data types: `char`, `int`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +Bits that are "bitwise ORed" with 0 are unchanged, so if myByte is a byte variable, +[source,arduino] +---- +myByte | B00000000 = myByte; +---- + +Bits that are "bitwise ORed" with 1 are set to 1 so: +[source,arduino] +---- +myByte | B11111111 = B11111111; +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero. +[%hardbreaks] + +Consequently - to set bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise OR operator (|=) with the constant B00000011 + + 1 0 1 0 1 0 1 0 variable + 0 0 0 0 0 0 1 1 mask + ---------------------- + 1 0 1 0 1 0 1 1 + + bits unchanged + bits set + + +Here is the same representation with the variables bits replaced with the symbol x + + x x x x x x x x variable + 0 0 0 0 0 0 1 1 mask + ---------------------- + x x x x x x 1 1 + + bits unchanged + bits set + +So if: +[source,arduino] +---- +myByte = B10101010; +myByte |= B00000011 == B10101011; +---- + +-- +// HOW TO USE SECTION ENDS + + + + +//SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../bitwise-operators/bitwiseor[| Bitwise OR] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundBitwiseXor.adoc b/Language/Structure/Compound Operators/compoundBitwiseXor.adoc index 95758430c..267d44fd9 100644 --- a/Language/Structure/Compound Operators/compoundBitwiseXor.adoc +++ b/Language/Structure/Compound Operators/compoundBitwiseXor.adoc @@ -1,112 +1,112 @@ ---- -title: "^=" -title_expanded: compound bitwise xor -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - -= ^= Compound Bitwise XOR - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The compound bitwise XOR operator `^=` is often used with a variable and a constant to toggle (invert) particular bits in a variable. -[%hardbreaks] - -A review of the Bitwise XOR `^` operator: - - 0 0 1 1 operand1 - 0 1 0 1 operand2 - ---------- - 0 1 1 0 (operand1 ^ operand2) - returned result -[%hardbreaks] - -[float] -=== Syntax -`x ^= y; // equivalent to x = x ^ y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `char`, `int`, `long`. + -`y`: variable or constant. Allowed data types: `char`, `int`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -Bits that are "bitwise XORed" with 0 are left unchanged. So if myByte is a byte variable, -[source,arduino] ----- -myByte ^ B00000000 = myByte; ----- - -Bits that are "bitwise XORed" with 1 are toggled so: -[source,arduino] ----- -myByte ^ B11111111 = ~myByte; ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero. -[%hardbreaks] - -Consequently - to toggle bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise XOR operator (^=) with the constant B00000011 - - 1 0 1 0 1 0 1 0 variable - 0 0 0 0 0 0 1 1 mask - ---------------------- - 1 0 1 0 1 0 0 1 - - bits unchanged - bits toggled - - -Here is the same representation with the variables bits replaced with the symbol x. ~x represents the complement of x. - - x x x x x x x x variable - 0 0 0 0 0 0 1 1 mask - ---------------------- - x x x x x x ~x ~x - - bits unchanged - bits set - -So if: -[source,arduino] ----- -myByte = B10101010; -myByte ^= B00000011 == B10101001; ----- - --- -// HOW TO USE SECTION ENDS - - - - -//SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../bitwise-operators/bitwisexor[^ Bitwise XOR] - --- -// SEE ALSO SECTION ENDS +--- +title: "^=" +title_expanded: compound bitwise xor +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + += ^= Compound Bitwise XOR + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The compound bitwise XOR operator `^=` is often used with a variable and a constant to toggle (invert) particular bits in a variable. +[%hardbreaks] + +A review of the Bitwise XOR `^` operator: + + 0 0 1 1 operand1 + 0 1 0 1 operand2 + ---------- + 0 1 1 0 (operand1 ^ operand2) - returned result +[%hardbreaks] + +[float] +=== Syntax +`x ^= y; // equivalent to x = x ^ y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `char`, `int`, `long`. + +`y`: variable or constant. Allowed data types: `char`, `int`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +Bits that are "bitwise XORed" with 0 are left unchanged. So if myByte is a byte variable, +[source,arduino] +---- +myByte ^ B00000000 = myByte; +---- + +Bits that are "bitwise XORed" with 1 are toggled so: +[source,arduino] +---- +myByte ^ B11111111 = ~myByte; +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero. +[%hardbreaks] + +Consequently - to toggle bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise XOR operator (^=) with the constant B00000011 + + 1 0 1 0 1 0 1 0 variable + 0 0 0 0 0 0 1 1 mask + ---------------------- + 1 0 1 0 1 0 0 1 + + bits unchanged + bits toggled + + +Here is the same representation with the variables bits replaced with the symbol x. ~x represents the complement of x. + + x x x x x x x x variable + 0 0 0 0 0 0 1 1 mask + ---------------------- + x x x x x x ~x ~x + + bits unchanged + bits set + +So if: +[source,arduino] +---- +myByte = B10101010; +myByte ^= B00000011 == B10101001; +---- + +-- +// HOW TO USE SECTION ENDS + + + + +//SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../bitwise-operators/bitwisexor[^ Bitwise XOR] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundDivision.adoc b/Language/Structure/Compound Operators/compoundDivision.adoc index 9a5e73f5e..019ef5952 100644 --- a/Language/Structure/Compound Operators/compoundDivision.adoc +++ b/Language/Structure/Compound Operators/compoundDivision.adoc @@ -1,71 +1,71 @@ ---- -title: "/=" -title_expanded: compound division -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= /= Compound Division - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -This is a convenient shorthand to perform division of a variable with another constant or variable. -[%hardbreaks] - - -[float] -=== Syntax -`x /= y; // equivalent to the expression x = x / y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`y`: *non zero* variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -x = 2; -x /= 2; // x now contains 1 ----- -[%hardbreaks] - - --- -// HOW TO USE SECTION ENDS - - - -//SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../arithmetic-operators/division[Normal Division] - --- -// SEE ALSO SECTION ENDS +--- +title: "/=" +title_expanded: compound division +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += /= Compound Division + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +This is a convenient shorthand to perform division of a variable with another constant or variable. +[%hardbreaks] + + +[float] +=== Syntax +`x /= y; // equivalent to the expression x = x / y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`y`: *non zero* variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +x = 2; +x /= 2; // x now contains 1 +---- +[%hardbreaks] + + +-- +// HOW TO USE SECTION ENDS + + + +//SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../arithmetic-operators/division[Normal Division] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundMultiplication.adoc b/Language/Structure/Compound Operators/compoundMultiplication.adoc index 436d39958..b2ec543ab 100644 --- a/Language/Structure/Compound Operators/compoundMultiplication.adoc +++ b/Language/Structure/Compound Operators/compoundMultiplication.adoc @@ -1,71 +1,71 @@ ---- -title: "*=" -title_expanded: compound multiplication -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= *= Compound Multiplication - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -This is a convenient shorthand to perform multiplication of a variable with another constant or variable. -[%hardbreaks] - - -[float] -=== Syntax -`x *= y; // equivalent to the expression x = x * y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`y`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -x = 2; -x *= 2; // x now contains 4 ----- - - --- -// HOW TO USE SECTION ENDS - - - - -//SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../arithmetic-operators/multiplication[Normal Multiplication] - --- -// SEE ALSO SECTION ENDS +--- +title: "*=" +title_expanded: compound multiplication +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += *= Compound Multiplication + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +This is a convenient shorthand to perform multiplication of a variable with another constant or variable. +[%hardbreaks] + + +[float] +=== Syntax +`x *= y; // equivalent to the expression x = x * y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`y`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +x = 2; +x *= 2; // x now contains 4 +---- + + +-- +// HOW TO USE SECTION ENDS + + + + +//SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../arithmetic-operators/multiplication[Normal Multiplication] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundRemainder.adoc b/Language/Structure/Compound Operators/compoundRemainder.adoc index f60328063..e4722c298 100644 --- a/Language/Structure/Compound Operators/compoundRemainder.adoc +++ b/Language/Structure/Compound Operators/compoundRemainder.adoc @@ -1,78 +1,78 @@ ---- -title: "%=" -title_expanded: compound remainder -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= %= Compound Remainder - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -This is a convenient shorthand to calculate the remainder when one integer is divided by another and assign it back to the variable the calculation was done on. -[%hardbreaks] - - -[float] -=== Syntax -`x %= divisor; // equivalent to the expression x = x % divisor;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`. + -`divisor`: *non zero* variable or constant. Allowed data types: `int`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int x = 7; -x %= 5; // x now contains 2 ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -1. The compound remainder operator does not work on floats. - -2. If the *first* operand is negative, the result is negative (or zero). -Therefore, the result of `x %= 10` will not always be between 0 and 9 if `x` can be negative. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - -//SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../arithmetic-operators/remainder[Remainder] - --- -// SEE ALSO SECTION ENDS +--- +title: "%=" +title_expanded: compound remainder +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += %= Compound Remainder + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +This is a convenient shorthand to calculate the remainder when one integer is divided by another and assign it back to the variable the calculation was done on. +[%hardbreaks] + + +[float] +=== Syntax +`x %= divisor; // equivalent to the expression x = x % divisor;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`. + +`divisor`: *non zero* variable or constant. Allowed data types: `int`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int x = 7; +x %= 5; // x now contains 2 +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +1. The compound remainder operator does not work on floats. + +2. If the *first* operand is negative, the result is negative (or zero). +Therefore, the result of `x %= 10` will not always be between 0 and 9 if `x` can be negative. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + +//SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../arithmetic-operators/remainder[Remainder] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/compoundSubtraction.adoc b/Language/Structure/Compound Operators/compoundSubtraction.adoc index 417edb0cd..22ca964a4 100644 --- a/Language/Structure/Compound Operators/compoundSubtraction.adoc +++ b/Language/Structure/Compound Operators/compoundSubtraction.adoc @@ -1,69 +1,69 @@ ---- -title: "-=" -title_expanded: compound subtraction -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= -= Compound Subtraction - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -This is a convenient shorthand to perform subtraction of a constant or a variable from a variable. -[%hardbreaks] - - -[float] -=== Syntax -`x -= y; // equivalent to the expression x = x - y;` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + -`y`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -x = 20; -x -= 2; // x now contains 18 ----- - - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../arithmetic-operators/subtraction[Normal Subtraction] - --- -// SEE ALSO SECTION ENDS +--- +title: "-=" +title_expanded: compound subtraction +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += -= Compound Subtraction + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +This is a convenient shorthand to perform subtraction of a constant or a variable from a variable. +[%hardbreaks] + + +[float] +=== Syntax +`x -= y; // equivalent to the expression x = x - y;` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +`y`: variable or constant. Allowed data types: `int`, `float`, `double`, `byte`, `short`, `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +x = 20; +x -= 2; // x now contains 18 +---- + + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../arithmetic-operators/subtraction[Normal Subtraction] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/decrement.adoc b/Language/Structure/Compound Operators/decrement.adoc index 8b9bdc84e..752b1d182 100644 --- a/Language/Structure/Compound Operators/decrement.adoc +++ b/Language/Structure/Compound Operators/decrement.adoc @@ -1,74 +1,74 @@ ---- -title: "--" -title_expanded: decrement -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= -- Decrement - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Decrements the value of a variable by 1. -[%hardbreaks] - - -[float] -=== Syntax -`x--; // decrement x by one and returns the old value of x` + -`--x; // decrement x by one and returns the new value of x` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`, `long` (possibly unsigned). - - -[float] -=== Returns -The original or newly decremented value of the variable. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -x = 2; -y = --x; // x now contains 1, y contains 1 -y = x--; // x contains 0, but y still contains 1 ----- - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "--" +title_expanded: decrement +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += -- Decrement + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Decrements the value of a variable by 1. +[%hardbreaks] + + +[float] +=== Syntax +`x--; // decrement x by one and returns the old value of x` + +`--x; // decrement x by one and returns the new value of x` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`, `long` (possibly unsigned). + + +[float] +=== Returns +The original or newly decremented value of the variable. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +x = 2; +y = --x; // x now contains 1, y contains 1 +y = x--; // x contains 0, but y still contains 1 +---- + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Compound Operators/increment.adoc b/Language/Structure/Compound Operators/increment.adoc index 00c32070b..b9dd49b7b 100644 --- a/Language/Structure/Compound Operators/increment.adoc +++ b/Language/Structure/Compound Operators/increment.adoc @@ -1,72 +1,72 @@ ---- -title: "++" -title_expanded: increment -categories: [ "Structure" ] -subCategories: [ "Compound Operators" ] ---- - - - - - -= ++ Increment - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Increments the value of a variable by 1. -[%hardbreaks] - - -[float] -=== Syntax -`x++; // increment x by one and returns the old value of x` + -`++x; // increment x by one and returns the new value of x` - - -[float] -=== Parameters -`x`: variable. Allowed data types: `int`, `long` (possibly unsigned). - -[float] -=== Returns -The original or newly incremented value of the variable. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -x = 2; -y = ++x; // x now contains 3, y contains 3 -y = x++; // x contains 4, but y still contains 3 ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "++" +title_expanded: increment +categories: [ "Structure" ] +subCategories: [ "Compound Operators" ] +--- + + + + + += ++ Increment + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Increments the value of a variable by 1. +[%hardbreaks] + + +[float] +=== Syntax +`x++; // increment x by one and returns the old value of x` + +`++x; // increment x by one and returns the new value of x` + + +[float] +=== Parameters +`x`: variable. Allowed data types: `int`, `long` (possibly unsigned). + +[float] +=== Returns +The original or newly incremented value of the variable. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +x = 2; +y = ++x; // x now contains 3, y contains 3 +y = x++; // x contains 4, but y still contains 3 +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/break.adoc b/Language/Structure/Control Structure/break.adoc index 8d6a33087..63bb798ca 100644 --- a/Language/Structure/Control Structure/break.adoc +++ b/Language/Structure/Control Structure/break.adoc @@ -1,65 +1,65 @@ ---- -title: break -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= break - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -[%hardbreaks] -`break` is used to exit from a link:../for[for], link:../while[while] or link:../dowhile[do...while] loop, bypassing the normal loop condition. It is also used to exit from a link:../switchcase[switch case] statement. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- -[float] -=== Example Code -In the following code, the control exits the `for` loop when the sensor value exceeds the threshold. -[source,arduino] ----- -int threshold = 40; -for (int x = 0; x < 255; x++) { - analogWrite(PWMpin, x); - sens = analogRead(sensorPin); - if (sens > threshold) { // bail out on sensor detect - x = 0; - break; - } - delay(50); -} ----- - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: break +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += break + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +[%hardbreaks] +`break` is used to exit from a link:../for[for], link:../while[while] or link:../dowhile[do...while] loop, bypassing the normal loop condition. It is also used to exit from a link:../switchcase[switch case] statement. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- +[float] +=== Example Code +In the following code, the control exits the `for` loop when the sensor value exceeds the threshold. +[source,arduino] +---- +int threshold = 40; +for (int x = 0; x < 255; x++) { + analogWrite(PWMpin, x); + sens = analogRead(sensorPin); + if (sens > threshold) { // bail out on sensor detect + x = 0; + break; + } + delay(50); +} +---- + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/continue.adoc b/Language/Structure/Control Structure/continue.adoc index 9aa491c33..505a28679 100644 --- a/Language/Structure/Control Structure/continue.adoc +++ b/Language/Structure/Control Structure/continue.adoc @@ -1,65 +1,65 @@ ---- -title: continue -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= continue - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -[%hardbreaks] -The `continue` statement skips the rest of the current iteration of a loop (link:../for[for], link:../while[while], or link:../dowhile[do...while]). It continues by checking the conditional expression of the loop, and proceeding with any subsequent iterations. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -The following code writes the value of 0 to 255 to the `PWMpin`, but skips the values in the range of 41 to 119. -[source,arduino] ----- -for (int x = 0; x <= 255; x ++) { - if (x > 40 && x < 120) { // create jump in values - continue; - } - - analogWrite(PWMpin, x); - delay(50); -} ----- - - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: continue +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += continue + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +[%hardbreaks] +The `continue` statement skips the rest of the current iteration of a loop (link:../for[for], link:../while[while], or link:../dowhile[do...while]). It continues by checking the conditional expression of the loop, and proceeding with any subsequent iterations. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +The following code writes the value of 0 to 255 to the `PWMpin`, but skips the values in the range of 41 to 119. +[source,arduino] +---- +for (int x = 0; x <= 255; x ++) { + if (x > 40 && x < 120) { // create jump in values + continue; + } + + analogWrite(PWMpin, x); + delay(50); +} +---- + + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/doWhile.adoc b/Language/Structure/Control Structure/doWhile.adoc index 6c79fa192..672ff5919 100644 --- a/Language/Structure/Control Structure/doWhile.adoc +++ b/Language/Structure/Control Structure/doWhile.adoc @@ -1,74 +1,74 @@ ---- -title: do...while -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= do...while loop - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -[%hardbreaks] -The `do...while` loop works in the same manner as the link:../while[while] loop, with the exception that the condition is tested at the end of the loop, so the do loop will always run at least once. - -[float] -=== Syntax -[source,arduino] ----- -do { - // statement block -} while (condition); ----- - - -[float] -=== Parameters -`condition`: a boolean expression that evaluates to `true` or `false`. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int x = 0; -do { - delay(50); // wait for sensors to stabilize - x = readSensors(); // check the sensors -} while (x < 100); ----- - - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: do...while +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += do...while loop + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +[%hardbreaks] +The `do...while` loop works in the same manner as the link:../while[while] loop, with the exception that the condition is tested at the end of the loop, so the do loop will always run at least once. + +[float] +=== Syntax +[source,arduino] +---- +do { + // statement block +} while (condition); +---- + + +[float] +=== Parameters +`condition`: a boolean expression that evaluates to `true` or `false`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int x = 0; +do { + delay(50); // wait for sensors to stabilize + x = readSensors(); // check the sensors +} while (x < 100); +---- + + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/else.adoc b/Language/Structure/Control Structure/else.adoc index 3b4a8fdc2..cbc4f5010 100644 --- a/Language/Structure/Control Structure/else.adoc +++ b/Language/Structure/Control Structure/else.adoc @@ -1,82 +1,82 @@ ---- -title: else -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= if...else - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The `if...else` allows greater control over the flow of code than the basic link:../if[if] statement, by allowing multiple tests to be grouped together. An `else` clause (if at all exists) will be executed if the condition in the `if` statement results in `false`. The `else` can proceed another `if` test, so that multiple, mutually exclusive tests can be run at the same time. -[%hardbreaks] - -Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default `else` block is executed, if one is present, and sets the default behavior. -[%hardbreaks] - -Note that an `else if` block may be used with or without a terminating `else` block and vice versa. An unlimited number of such `else if` branches is allowed. - -[float] -=== Syntax -[source,arduino] ----- -if (condition1) { - // do Thing A -} -else if (condition2) { - // do Thing B -} -else { - // do Thing C -} ----- - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- -[float] -=== Example Code -Below is an extract from a code for temperature sensor system -[source,arduino] ----- -if (temperature >= 70) { - //Danger! Shut down the system -} -else if (temperature >= 60 && temperature < 70) { - //Warning! User attention required -} -else { - //Safe! Continue usual tasks... -} ----- - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: else +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += if...else + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The `if...else` allows greater control over the flow of code than the basic link:../if[if] statement, by allowing multiple tests to be grouped together. An `else` clause (if at all exists) will be executed if the condition in the `if` statement results in `false`. The `else` can proceed another `if` test, so that multiple, mutually exclusive tests can be run at the same time. +[%hardbreaks] + +Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default `else` block is executed, if one is present, and sets the default behavior. +[%hardbreaks] + +Note that an `else if` block may be used with or without a terminating `else` block and vice versa. An unlimited number of such `else if` branches is allowed. + +[float] +=== Syntax +[source,arduino] +---- +if (condition1) { + // do Thing A +} +else if (condition2) { + // do Thing B +} +else { + // do Thing C +} +---- + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- +[float] +=== Example Code +Below is an extract from a code for temperature sensor system +[source,arduino] +---- +if (temperature >= 70) { + //Danger! Shut down the system +} +else if (temperature >= 60 && temperature < 70) { + //Warning! User attention required +} +else { + //Safe! Continue usual tasks... +} +---- + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/for.adoc b/Language/Structure/Control Structure/for.adoc index e37b222eb..ef56739ba 100644 --- a/Language/Structure/Control Structure/for.adoc +++ b/Language/Structure/Control Structure/for.adoc @@ -1,118 +1,118 @@ ---- -title: for -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= for loop - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The `for` statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The `for` statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins. -[%hardbreaks] - - -[float] -=== Syntax -[source,arduino] ----- -for (initialization; condition; increment) { - // statement(s); -} ----- - - -[float] -=== Parameters -`initialization`: happens first and exactly once. + -`condition`: each time through the loop, `condition` is tested; if it's `true`, the statement block, and the *increment* is executed, then the *condition* is tested again. When the *condition* becomes `false`, the loop ends. + -`increment`: executed each time through the loop when `contition` is true. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -[source,arduino] ----- -// Dim an LED using a PWM pin -int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10 - -void setup() { - // no setup needed -} - -void loop() { - for (int i = 0; i <= 255; i++) { - analogWrite(PWMpin, i); - delay(10); - } -} ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -The C++ `for` loop is much more flexible than `for` loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C++ statements with unrelated variables, and use any C++ datatypes including floats. These types of unusual `for` statements may provide solutions to some rare programming problems. -[%hardbreaks] - -For example, using a multiplication in the increment line will generate a logarithmic progression: - -[source,arduino] ----- -for (int x = 2; x < 100; x = x * 1.5) { - println(x); -} ----- - -Generates: 2,3,4,6,9,13,19,28,42,63,94 -[%hardbreaks] - -Another example, fade an LED up and down with one `for` loop: - -[source,arduino] ----- -void loop() { - int x = 1; - for (int i = 0; i > -1; i = i + x) { - analogWrite(PWMpin, i); - if (i == 255) { - x = -1; // switch direction at peak - } - delay(10); - } -} ----- - - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: for +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += for loop + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The `for` statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The `for` statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins. +[%hardbreaks] + + +[float] +=== Syntax +[source,arduino] +---- +for (initialization; condition; increment) { + // statement(s); +} +---- + + +[float] +=== Parameters +`initialization`: happens first and exactly once. + +`condition`: each time through the loop, `condition` is tested; if it's `true`, the statement block, and the *increment* is executed, then the *condition* is tested again. When the *condition* becomes `false`, the loop ends. + +`increment`: executed each time through the loop when `contition` is true. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +[source,arduino] +---- +// Dim an LED using a PWM pin +int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10 + +void setup() { + // no setup needed +} + +void loop() { + for (int i = 0; i <= 255; i++) { + analogWrite(PWMpin, i); + delay(10); + } +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +The C++ `for` loop is much more flexible than `for` loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C++ statements with unrelated variables, and use any C++ datatypes including floats. These types of unusual `for` statements may provide solutions to some rare programming problems. +[%hardbreaks] + +For example, using a multiplication in the increment line will generate a logarithmic progression: + +[source,arduino] +---- +for (int x = 2; x < 100; x = x * 1.5) { + println(x); +} +---- + +Generates: 2,3,4,6,9,13,19,28,42,63,94 +[%hardbreaks] + +Another example, fade an LED up and down with one `for` loop: + +[source,arduino] +---- +void loop() { + int x = 1; + for (int i = 0; i > -1; i = i + x) { + analogWrite(PWMpin, i); + if (i == 255) { + x = -1; // switch direction at peak + } + delay(10); + } +} +---- + + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/goto.adoc b/Language/Structure/Control Structure/goto.adoc index 2e3e0e1e6..57de782cf 100644 --- a/Language/Structure/Control Structure/goto.adoc +++ b/Language/Structure/Control Structure/goto.adoc @@ -1,86 +1,86 @@ ---- -title: goto -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= goto - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Transfers program flow to a labeled point in the program -[%hardbreaks] - - -[float] -=== Syntax -[source,arduino] ----- -label: - -goto label; // sends program flow to the label ----- - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -for (byte r = 0; r < 255; r++) { - for (byte g = 255; g > 0; g--) { - for (byte b = 0; b < 255; b++) { - if (analogRead(0) > 250) { - goto bailout; - } - // more statements ... - } - } -} - -bailout: -// more statements ... ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -The use of `goto` is discouraged in C++ programming, and some authors of C++ programming books claim that the `goto` statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of `goto` statements, it is easy to create a program with undefined program flow, which can never be debugged. - -With that said, there are instances where a `goto` statement can come in handy, and simplify coding. One of these situations is to break out of deeply nested link:../for[for] loops, or link:../if[if] logic blocks, on a certain condition. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: goto +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += goto + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Transfers program flow to a labeled point in the program +[%hardbreaks] + + +[float] +=== Syntax +[source,arduino] +---- +label: + +goto label; // sends program flow to the label +---- + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +for (byte r = 0; r < 255; r++) { + for (byte g = 255; g > 0; g--) { + for (byte b = 0; b < 255; b++) { + if (analogRead(0) > 250) { + goto bailout; + } + // more statements ... + } + } +} + +bailout: +// more statements ... +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +The use of `goto` is discouraged in C++ programming, and some authors of C++ programming books claim that the `goto` statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of `goto` statements, it is easy to create a program with undefined program flow, which can never be debugged. + +With that said, there are instances where a `goto` statement can come in handy, and simplify coding. One of these situations is to break out of deeply nested link:../for[for] loops, or link:../if[if] logic blocks, on a certain condition. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/if.adoc b/Language/Structure/Control Structure/if.adoc index 1f637c298..f1a79934e 100644 --- a/Language/Structure/Control Structure/if.adoc +++ b/Language/Structure/Control Structure/if.adoc @@ -1,106 +1,106 @@ ---- -title: if -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= if - - -// OVERVIEW SECTION STARTS -[#overview] --- -[float] -=== Description -The `if` statement checks for a condition and executes the proceeding statement or set of statements if the condition is 'true'. -[%hardbreaks] - -[float] -=== Syntax -[source,arduino] ----- -if (condition) { - //statement(s) -} ----- - - -[float] -=== Parameters -`condition`: a boolean expression (i.e., can be `true` or `false`). - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -The brackets may be omitted after an if statement. If this is done, the next line (defined by the semicolon) becomes the only conditional statement. -[%hardbreaks] - -[source,arduino] ----- -if (x > 120) digitalWrite(LEDpin, HIGH); - -if (x > 120) -digitalWrite(LEDpin, HIGH); - -if (x > 120) {digitalWrite(LEDpin, HIGH);} - -if (x > 120) { - digitalWrite(LEDpin1, HIGH); - digitalWrite(LEDpin2, HIGH); -} -// all are correct ----- -[%hardbreaks] - - -[float] -=== Notes and Warnings -The statements being evaluated inside the parentheses require the use of one or more operators shown below. -[%hardbreaks] - -*Comparison Operators:* - - x == y (x is equal to y) - x != y (x is not equal to y) - x < y (x is less than y) - x > y (x is greater than y) - x <= y (x is less than or equal to y) - x >= y (x is greater than or equal to y) - - -Beware of accidentally using the single equal sign (e.g. `if (x = 10)` ). The single equal sign is the assignment operator, and sets `x` to 10 (puts the value 10 into the variable `x`). Instead use the double equal sign (e.g. `if (x == 10)` ), which is the comparison operator, and tests _whether_ `x` is equal to 10 or not. The latter statement is only true if `x` equals 10, but the former statement will always be true. - -This is because C++ evaluates the statement `if (x=10)` as follows: 10 is assigned to `x` (remember that the single equal sign is the (http://arduino.cc/en/Reference/Assignment[assignment operator^])), so `x` now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to `TRUE`, since any non-zero number evaluates to TRUE. Consequently, `if (x = 10)` will always evaluate to `TRUE`, which is not the desired result when using an 'if' statement. Additionally, the variable `x` will be set to 10, which is also not a desired action. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: if +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += if + + +// OVERVIEW SECTION STARTS +[#overview] +-- +[float] +=== Description +The `if` statement checks for a condition and executes the proceeding statement or set of statements if the condition is 'true'. +[%hardbreaks] + +[float] +=== Syntax +[source,arduino] +---- +if (condition) { + //statement(s) +} +---- + + +[float] +=== Parameters +`condition`: a boolean expression (i.e., can be `true` or `false`). + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +The brackets may be omitted after an if statement. If this is done, the next line (defined by the semicolon) becomes the only conditional statement. +[%hardbreaks] + +[source,arduino] +---- +if (x > 120) digitalWrite(LEDpin, HIGH); + +if (x > 120) +digitalWrite(LEDpin, HIGH); + +if (x > 120) {digitalWrite(LEDpin, HIGH);} + +if (x > 120) { + digitalWrite(LEDpin1, HIGH); + digitalWrite(LEDpin2, HIGH); +} +// all are correct +---- +[%hardbreaks] + + +[float] +=== Notes and Warnings +The statements being evaluated inside the parentheses require the use of one or more operators shown below. +[%hardbreaks] + +*Comparison Operators:* + + x == y (x is equal to y) + x != y (x is not equal to y) + x < y (x is less than y) + x > y (x is greater than y) + x <= y (x is less than or equal to y) + x >= y (x is greater than or equal to y) + + +Beware of accidentally using the single equal sign (e.g. `if (x = 10)` ). The single equal sign is the assignment operator, and sets `x` to 10 (puts the value 10 into the variable `x`). Instead use the double equal sign (e.g. `if (x == 10)` ), which is the comparison operator, and tests _whether_ `x` is equal to 10 or not. The latter statement is only true if `x` equals 10, but the former statement will always be true. + +This is because C++ evaluates the statement `if (x=10)` as follows: 10 is assigned to `x` (remember that the single equal sign is the (http://arduino.cc/en/Reference/Assignment[assignment operator^])), so `x` now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to `TRUE`, since any non-zero number evaluates to TRUE. Consequently, `if (x = 10)` will always evaluate to `TRUE`, which is not the desired result when using an 'if' statement. Additionally, the variable `x` will be set to 10, which is also not a desired action. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/return.adoc b/Language/Structure/Control Structure/return.adoc index b098d79b2..abd53be57 100644 --- a/Language/Structure/Control Structure/return.adoc +++ b/Language/Structure/Control Structure/return.adoc @@ -1,90 +1,90 @@ ---- -title: return -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= return - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Terminate a function and return a value from a function to the calling function, if desired. -[%hardbreaks] - - -[float] -=== Syntax -`return;` + -`return value;` - - -[float] -=== Parameters -`value`: Allowed data types: any variable or constant type. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -A function to compare a sensor input to a threshold - -[source,arduino] ----- -int checkSensor() { - if (analogRead(0) > 400) { - return 1; - } - else { - return 0; - } -} ----- - -The return keyword is handy to test a section of code without having to "comment out" large sections of possibly buggy code. -[source,arduino] ----- -void loop() { - // brilliant code idea to test here - - return; - - // the rest of a dysfunctional sketch here - // this code will never be executed -} ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: return +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += return + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Terminate a function and return a value from a function to the calling function, if desired. +[%hardbreaks] + + +[float] +=== Syntax +`return;` + +`return value;` + + +[float] +=== Parameters +`value`: Allowed data types: any variable or constant type. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +A function to compare a sensor input to a threshold + +[source,arduino] +---- +int checkSensor() { + if (analogRead(0) > 400) { + return 1; + } + else { + return 0; + } +} +---- + +The return keyword is handy to test a section of code without having to "comment out" large sections of possibly buggy code. +[source,arduino] +---- +void loop() { + // brilliant code idea to test here + + return; + + // the rest of a dysfunctional sketch here + // this code will never be executed +} +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/switchCase.adoc b/Language/Structure/Control Structure/switchCase.adoc index 959eba4d2..faa4a60a7 100644 --- a/Language/Structure/Control Structure/switchCase.adoc +++ b/Language/Structure/Control Structure/switchCase.adoc @@ -1,101 +1,101 @@ ---- -title: switch...case -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= switch...case statement - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Like link:../if[if] statements, link:../switchcase[switch case] controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. -[%hardbreaks] - -The link:../break[break] keyword exits the switch statement, and is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break, or the end of the switch statement is reached. -[%hardbreaks] - - -[float] -=== Syntax -[source,arduino] ----- -switch (var) { - case label1: - // statements - break; - case label2: - // statements - break; - default: - // statements - break; -} ----- - - -[float] -=== Parameters -`var`: a variable whose value to compare with various cases. Allowed data types: `int`, `char`. + -`label1`, `label2`: constants. Allowed data types: `int`, `char`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -switch (var) { - case 1: - //do something when var equals 1 - break; - case 2: - //do something when var equals 2 - break; - default: - // if nothing else matches, do the default - // default is optional - break; -} - ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTIN BEGINS -[#see_also] --- - -[float] -=== See also -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: switch...case +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += switch...case statement + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Like link:../if[if] statements, link:../switchcase[switch case] controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. +[%hardbreaks] + +The link:../break[break] keyword exits the switch statement, and is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break, or the end of the switch statement is reached. +[%hardbreaks] + + +[float] +=== Syntax +[source,arduino] +---- +switch (var) { + case label1: + // statements + break; + case label2: + // statements + break; + default: + // statements + break; +} +---- + + +[float] +=== Parameters +`var`: a variable whose value to compare with various cases. Allowed data types: `int`, `char`. + +`label1`, `label2`: constants. Allowed data types: `int`, `char`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +switch (var) { + case 1: + //do something when var equals 1 + break; + case 2: + //do something when var equals 2 + break; + default: + // if nothing else matches, do the default + // default is optional + break; +} + +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTIN BEGINS +[#see_also] +-- + +[float] +=== See also +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Control Structure/while.adoc b/Language/Structure/Control Structure/while.adoc index b0def2329..491cceb88 100644 --- a/Language/Structure/Control Structure/while.adoc +++ b/Language/Structure/Control Structure/while.adoc @@ -1,77 +1,77 @@ ---- -title: while -categories: [ "Structure" ] -subCategories: [ "Control Structure" ] ---- - - - - - -= while loop - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -[%hardbreaks] -A `while` loop will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the while loop will never exit. This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor. - -[float] -=== Syntax -[source,arduino] ----- -while (condition) { - // statement(s) -} ----- - - -[float] -=== Parameters -`condition`: a boolean expression that evaluates to `true` or `false`. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -var = 0; -while (var < 200) { - // do something repetitive 200 times - var++; -} ----- - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - -[role="example"] -* #EXAMPLE# https://arduino.cc/en/Tutorial/WhileLoop[While Loop^] - --- -// SEE ALSO SECTION ENDS +--- +title: while +categories: [ "Structure" ] +subCategories: [ "Control Structure" ] +--- + + + + + += while loop + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +[%hardbreaks] +A `while` loop will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the while loop will never exit. This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor. + +[float] +=== Syntax +[source,arduino] +---- +while (condition) { + // statement(s) +} +---- + + +[float] +=== Parameters +`condition`: a boolean expression that evaluates to `true` or `false`. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +var = 0; +while (var < 200) { + // do something repetitive 200 times + var++; +} +---- + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +[role="example"] +* #EXAMPLE# https://arduino.cc/en/Tutorial/WhileLoop[While Loop^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Further Syntax/blockComment.adoc b/Language/Structure/Further Syntax/blockComment.adoc index 92be3dfea..d8c200c9a 100644 --- a/Language/Structure/Further Syntax/blockComment.adoc +++ b/Language/Structure/Further Syntax/blockComment.adoc @@ -1,81 +1,81 @@ ---- -title: "/* */" -title_expanded: block comment -categories: [ "Structure" ] -subCategories: [ "Further Syntax" ] ---- - - - - - -= /* */ Block Comment - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Comments* are lines in the program that are used to inform yourself or others about the way the program works. They are ignored by the compiler, and not exported to the processor, so they don't take up any space in the microcontroller's flash memory. Comments' only purpose is to help you understand (or remember), or to inform others about how your program works. -[%hardbreaks] - -The beginning of a *block comment* or a *multi-line comment* is marked by the symbol `/\*` and the symbol `*/` marks its end. This type of a comment is called so as this can extend over more than one line; once the compiler reads the `/\*` it ignores whatever follows until it enounters a `*/`. - -// NOTE TO THE EDITOR: The '\' before the '*' in certain places are to escape the '*' from making the text bolder. -// In places were '\' is not used before '*', it is not actually required. --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -[source,arduino] ----- -/* This is a valid comment */ - -/* - Blink - Turns on an LED on for one second, then off for one second, repeatedly. - - This example code is in the public domain. - (Another valid comment) -*/ - -/* - if (gwb == 0) { // single line comment is OK inside a multi-line comment - x = 3; /* but not another multi-line comment - this is invalid */ - } -// don't forget the "closing" comment - they have to be balanced! -*/ ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -When experimenting with code, "commenting out" parts of your program is a convenient way to remove lines that may be buggy. This leaves the lines in the code, but turns them into comments, so the compiler just ignores them. This can be especially useful when trying to locate a problem, or when a program refuses to compile and the compiler error is cryptic or unhelpful. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "/* */" +title_expanded: block comment +categories: [ "Structure" ] +subCategories: [ "Further Syntax" ] +--- + + + + + += /* */ Block Comment + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Comments* are lines in the program that are used to inform yourself or others about the way the program works. They are ignored by the compiler, and not exported to the processor, so they don't take up any space in the microcontroller's flash memory. Comments' only purpose is to help you understand (or remember), or to inform others about how your program works. +[%hardbreaks] + +The beginning of a *block comment* or a *multi-line comment* is marked by the symbol `/\*` and the symbol `*/` marks its end. This type of a comment is called so as this can extend over more than one line; once the compiler reads the `/\*` it ignores whatever follows until it enounters a `*/`. + +// NOTE TO THE EDITOR: The '\' before the '*' in certain places are to escape the '*' from making the text bolder. +// In places were '\' is not used before '*', it is not actually required. +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +[source,arduino] +---- +/* This is a valid comment */ + +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + + This example code is in the public domain. + (Another valid comment) +*/ + +/* + if (gwb == 0) { // single line comment is OK inside a multi-line comment + x = 3; /* but not another multi-line comment - this is invalid */ + } +// don't forget the "closing" comment - they have to be balanced! +*/ +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When experimenting with code, "commenting out" parts of your program is a convenient way to remove lines that may be buggy. This leaves the lines in the code, but turns them into comments, so the compiler just ignores them. This can be especially useful when trying to locate a problem, or when a program refuses to compile and the compiler error is cryptic or unhelpful. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Further Syntax/define.adoc b/Language/Structure/Further Syntax/define.adoc index 4e92d28ee..3f65ce054 100644 --- a/Language/Structure/Further Syntax/define.adoc +++ b/Language/Structure/Further Syntax/define.adoc @@ -1,95 +1,95 @@ ---- -title: "#define" -title_expanded: define -categories: [ "Structure" ] -subCategories: [ "Further Syntax" ] ---- - - - - - -= #define - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -`#define` is a useful C++ component that allows the programmer to give a name to a constant value before the program is compiled. Defined constants in arduino don't take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time. -[%hardbreaks] - -This can have some unwanted side effects though, if for example, a constant name that had been #defined is included in some other constant or variable name. In that case the text would be replaced by the #defined number (or text). -[%hardbreaks] - -In general, the link:../../../variables/variable-scope\--qualifiers/const[const] keyword is preferred for defining constants and should be used instead of #define. -[%hardbreaks] - -[float] -=== Syntax -`#define constantName value` - - -[float] -=== Parameters -`constantName`: the name of the macro to define. + -`value`: the value to assign to the macro. - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -#define ledPin 3 -// The compiler will replace any mention of ledPin with the value 3 at compile time. ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -There is no semicolon after the #define statement. If you include one, the compiler will throw cryptic errors further down the page. - -[source,arduino] ----- -#define ledPin 3; // this is an error ----- - -Similarly, including an equal sign after the #define statement will also generate a cryptic compiler error further down the page. - -[source,arduino] ----- -#define ledPin = 3 // this is also an error ----- -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] -* #LANGUAGE# link:../../../variables/variable-scope\--qualifiers/const[const] -* #LANGUAGE# link:../../../variables/constants/constants[Constants] - --- -// SEE ALSO SECTION ENDS +--- +title: "#define" +title_expanded: define +categories: [ "Structure" ] +subCategories: [ "Further Syntax" ] +--- + + + + + += #define + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`#define` is a useful C++ component that allows the programmer to give a name to a constant value before the program is compiled. Defined constants in arduino don't take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time. +[%hardbreaks] + +This can have some unwanted side effects though, if for example, a constant name that had been #defined is included in some other constant or variable name. In that case the text would be replaced by the #defined number (or text). +[%hardbreaks] + +In general, the link:../../../variables/variable-scope\--qualifiers/const[const] keyword is preferred for defining constants and should be used instead of #define. +[%hardbreaks] + +[float] +=== Syntax +`#define constantName value` + + +[float] +=== Parameters +`constantName`: the name of the macro to define. + +`value`: the value to assign to the macro. + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +#define ledPin 3 +// The compiler will replace any mention of ledPin with the value 3 at compile time. +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +There is no semicolon after the #define statement. If you include one, the compiler will throw cryptic errors further down the page. + +[source,arduino] +---- +#define ledPin 3; // this is an error +---- + +Similarly, including an equal sign after the #define statement will also generate a cryptic compiler error further down the page. + +[source,arduino] +---- +#define ledPin = 3 // this is also an error +---- +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] +* #LANGUAGE# link:../../../variables/variable-scope\--qualifiers/const[const] +* #LANGUAGE# link:../../../variables/constants/constants[Constants] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Further Syntax/include.adoc b/Language/Structure/Further Syntax/include.adoc index f26c05049..f2fb9db86 100644 --- a/Language/Structure/Further Syntax/include.adoc +++ b/Language/Structure/Further Syntax/include.adoc @@ -1,85 +1,85 @@ ---- -title: "#include" -title_expanded: include -categories: [ "Structure" ] -subCategories: [ "Further Syntax" ] ---- - - - - - -= #include - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -`#include` is used to include outside libraries in your sketch. This gives the programmer access to a large group of standard C libraries (groups of pre-made functions), and also libraries written especially for Arduino. -[%hardbreaks] - -The main reference page for AVR C libraries (AVR is a reference to the Atmel chips on which the Arduino is based) is http://www.nongnu.org/avr-libc/user-manual/modules.html[here^]. -[%hardbreaks] - -Note that `#include`, similar to link:../define[`#define`], has no semicolon terminator, and the compiler will yield cryptic error messages if you add one. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -This example includes the Servo library so that its functions may be used to control a Servo motor. - - -[source,arduino] ----- -#include - -Servo myservo; // create servo object to control a servo - -void setup() { - myservo.attach(9); // attaches the servo on pin 9 to the servo object -} - -void loop() { - for (int pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees - // in steps of 1 degree - myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position - } - for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees - myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position - } -} ----- - - --- -// HOW TO USE SECTION ENDS - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - - --- -// SEE ALSO SECTION ENDS +--- +title: "#include" +title_expanded: include +categories: [ "Structure" ] +subCategories: [ "Further Syntax" ] +--- + + + + + += #include + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +`#include` is used to include outside libraries in your sketch. This gives the programmer access to a large group of standard C libraries (groups of pre-made functions), and also libraries written especially for Arduino. +[%hardbreaks] + +The main reference page for AVR C libraries (AVR is a reference to the Atmel chips on which the Arduino is based) is http://www.nongnu.org/avr-libc/user-manual/modules.html[here^]. +[%hardbreaks] + +Note that `#include`, similar to link:../define[`#define`], has no semicolon terminator, and the compiler will yield cryptic error messages if you add one. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +This example includes the Servo library so that its functions may be used to control a Servo motor. + + +[source,arduino] +---- +#include + +Servo myservo; // create servo object to control a servo + +void setup() { + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() { + for (int pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees + // in steps of 1 degree + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } + for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } +} +---- + + +-- +// HOW TO USE SECTION ENDS + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Further Syntax/semicolon.adoc b/Language/Structure/Further Syntax/semicolon.adoc index 74e379e29..6a9a1d2ba 100644 --- a/Language/Structure/Further Syntax/semicolon.adoc +++ b/Language/Structure/Further Syntax/semicolon.adoc @@ -1,64 +1,64 @@ ---- -title: ";" -title_expanded: semicolon -categories: [ "Structure" ] -subCategories: [ "Further Syntax" ] ---- - - - - - -= ; Semicolon - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Used to end a statement. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int a = 13; ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Forgetting to end a line in a semicolon will result in a compiler error. The error text may be obvious, and refer to a missing semicolon, or it may not. If an impenetrable or seemingly illogical compiler error comes up, one of the first things to check is a missing semicolon, in the immediate vicinity, preceding the line at which the compiler complained. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: ";" +title_expanded: semicolon +categories: [ "Structure" ] +subCategories: [ "Further Syntax" ] +--- + + + + + += ; Semicolon + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Used to end a statement. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int a = 13; +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Forgetting to end a line in a semicolon will result in a compiler error. The error text may be obvious, and refer to a missing semicolon, or it may not. If an impenetrable or seemingly illogical compiler error comes up, one of the first things to check is a missing semicolon, in the immediate vicinity, preceding the line at which the compiler complained. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Further Syntax/singleLineComment.adoc b/Language/Structure/Further Syntax/singleLineComment.adoc index c3b85231e..3bf2f8ae0 100644 --- a/Language/Structure/Further Syntax/singleLineComment.adoc +++ b/Language/Structure/Further Syntax/singleLineComment.adoc @@ -1,70 +1,70 @@ ---- -title: "//" -title_expanded: single line comment -categories: [ "Structure" ] -subCategories: [ "Further Syntax" ] ---- - - - - - -= // Single Line Comment - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -*Comments* are lines in the program that are used to inform yourself or others about the way the program works. They are ignored by the compiler, and not exported to the processor, so they don't take up any space in the microcontroller's flash memory. Comments' only purpose is to help you understand (or remember), or to inform others about how your program works. -[%hardbreaks] - -A *single line comment* begins with `//` (two adjacent slashes). This comment ends automatically at the end of a line. whatever follows `//` till the end of a line will be ignored by the compiler. --- -// OVERVIEW SECTION ENDS - - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -There are two different ways of marking a line as a comment: - -[source,arduino] ----- -// pin 13 has an LED connected on most Arduino boards. -// give it a name: -int led = 13; -digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -When experimenting with code, "commenting out" parts of your program is a convenient way to remove lines that may be buggy. This leaves the lines in the code, but turns them into comments, so the compiler just ignores them. This can be especially useful when trying to locate a problem, or when a program refuses to compile and the compiler error is cryptic or unhelpful. -[%hardbreaks] - - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "//" +title_expanded: single line comment +categories: [ "Structure" ] +subCategories: [ "Further Syntax" ] +--- + + + + + += // Single Line Comment + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +*Comments* are lines in the program that are used to inform yourself or others about the way the program works. They are ignored by the compiler, and not exported to the processor, so they don't take up any space in the microcontroller's flash memory. Comments' only purpose is to help you understand (or remember), or to inform others about how your program works. +[%hardbreaks] + +A *single line comment* begins with `//` (two adjacent slashes). This comment ends automatically at the end of a line. whatever follows `//` till the end of a line will be ignored by the compiler. +-- +// OVERVIEW SECTION ENDS + + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +There are two different ways of marking a line as a comment: + +[source,arduino] +---- +// pin 13 has an LED connected on most Arduino boards. +// give it a name: +int led = 13; +digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +When experimenting with code, "commenting out" parts of your program is a convenient way to remove lines that may be buggy. This leaves the lines in the code, but turns them into comments, so the compiler just ignores them. This can be especially useful when trying to locate a problem, or when a program refuses to compile and the compiler error is cryptic or unhelpful. +[%hardbreaks] + + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Pointer Access Operators/dereference.adoc b/Language/Structure/Pointer Access Operators/dereference.adoc index 39cf88746..6785e5c9d 100644 --- a/Language/Structure/Pointer Access Operators/dereference.adoc +++ b/Language/Structure/Pointer Access Operators/dereference.adoc @@ -1,71 +1,71 @@ ---- -title: "*" -title_expanded: dereference operator -categories: [ "Structure" ] -subCategories: [ "Pointer Access Operators" ] ---- - - - - - -= * Dereference Operator - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Dereferencing is one of the features specifically for use with pointers. The asterisk operator `*` is used for this purpose. If `p` is a pointer, then `*p` represents the value contained in the address pointed by `p`. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int *p; // declare a pointer to an int data type -int i = 5; -int result = 0; -p = &i; // now 'p' contains the address of 'i' -result = *p; // 'result' gets the value at the address pointed by 'p' - // i.e., it gets the value of 'i' which is 5 ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Pointers are one of the complicated subjects for beginners in learning C, and it is possible to write the vast majority of Arduino sketches without ever encountering pointers. However for manipulating certain data structures, the use of pointers can simplify the code, and and knowledge of manipulating pointers is handy to have in one's toolkit. -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - -[role="definition"] -* #DEFINITION# https://en.wikipedia.org/wiki/Pointer_%28computer_programming%29[Pointers^] - --- -// SEE ALSO SECTION ENDS +--- +title: "*" +title_expanded: dereference operator +categories: [ "Structure" ] +subCategories: [ "Pointer Access Operators" ] +--- + + + + + += * Dereference Operator + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Dereferencing is one of the features specifically for use with pointers. The asterisk operator `*` is used for this purpose. If `p` is a pointer, then `*p` represents the value contained in the address pointed by `p`. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int *p; // declare a pointer to an int data type +int i = 5; +int result = 0; +p = &i; // now 'p' contains the address of 'i' +result = *p; // 'result' gets the value at the address pointed by 'p' + // i.e., it gets the value of 'i' which is 5 +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Pointers are one of the complicated subjects for beginners in learning C, and it is possible to write the vast majority of Arduino sketches without ever encountering pointers. However for manipulating certain data structures, the use of pointers can simplify the code, and and knowledge of manipulating pointers is handy to have in one's toolkit. +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +[role="definition"] +* #DEFINITION# https://en.wikipedia.org/wiki/Pointer_%28computer_programming%29[Pointers^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Pointer Access Operators/reference.adoc b/Language/Structure/Pointer Access Operators/reference.adoc index 2d8d6d24f..eaf220b23 100644 --- a/Language/Structure/Pointer Access Operators/reference.adoc +++ b/Language/Structure/Pointer Access Operators/reference.adoc @@ -1,72 +1,72 @@ ---- -title: "&" -title_expanded: reference operator -categories: [ "Structure" ] -subCategories: [ "Pointer Access Operators" ] ---- - - - - - -= & Reference Operator - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Referencing is one of the features specifically for use with pointers. The ampersand operator `&` is used for this purpose. If `x` is a variable, then `&x` represents the address of the variable `x`. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int *p; // declare a pointer to an int data type -int i = 5; -int result = 0; -p = &i; // now 'p' contains the address of 'i' -result = *p; // 'result' gets the value at the address pointed by 'p' - // i.e., it gets the value of 'i' which is 5 ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Pointers are one of the complicated subjects for beginners in learning C, and it is possible to write the vast majority of Arduino sketches without ever encountering pointers. However for manipulating certain data structures, the use of pointers can simplify the code, and knowledge of manipulating pointers is handy to have in one's toolkit. -[%hardbreaks] - - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - -[role="definition"] -* #DEFINITION# https://en.wikipedia.org/wiki/Pointer_%28computer_programming%29[Pointers^] - --- -// SEE ALSO SECTION ENDS +--- +title: "&" +title_expanded: reference operator +categories: [ "Structure" ] +subCategories: [ "Pointer Access Operators" ] +--- + + + + + += & Reference Operator + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Referencing is one of the features specifically for use with pointers. The ampersand operator `&` is used for this purpose. If `x` is a variable, then `&x` represents the address of the variable `x`. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int *p; // declare a pointer to an int data type +int i = 5; +int result = 0; +p = &i; // now 'p' contains the address of 'i' +result = *p; // 'result' gets the value at the address pointed by 'p' + // i.e., it gets the value of 'i' which is 5 +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Pointers are one of the complicated subjects for beginners in learning C, and it is possible to write the vast majority of Arduino sketches without ever encountering pointers. However for manipulating certain data structures, the use of pointers can simplify the code, and knowledge of manipulating pointers is handy to have in one's toolkit. +[%hardbreaks] + + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +[role="definition"] +* #DEFINITION# https://en.wikipedia.org/wiki/Pointer_%28computer_programming%29[Pointers^] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Sketch/loop.adoc b/Language/Structure/Sketch/loop.adoc index f4ef12eed..8586e44c0 100644 --- a/Language/Structure/Sketch/loop.adoc +++ b/Language/Structure/Sketch/loop.adoc @@ -1,69 +1,69 @@ ---- -title: loop() -categories: [ "Functions" ] -subCategories: [ "Sketch" ] ---- - - - - - -= loop() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -After creating a link:../setup[setup()] function, which initializes and sets the initial values, the `loop()` function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -[source,arduino] ----- -int buttonPin = 3; - -// setup initializes serial and the button pin -void setup() { - Serial.begin(9600); - pinMode(buttonPin, INPUT); -} - -// loop checks the button pin each time, -// and will send serial if it is pressed -void loop() { - if (digitalRead(buttonPin) == HIGH) { - Serial.write('H'); - } - else { - Serial.write('L'); - } - - delay(1000); -} ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - --- -// SEE ALSO SECTION ENDS +--- +title: loop() +categories: [ "Functions" ] +subCategories: [ "Sketch" ] +--- + + + + + += loop() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +After creating a link:../setup[setup()] function, which initializes and sets the initial values, the `loop()` function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +[source,arduino] +---- +int buttonPin = 3; + +// setup initializes serial and the button pin +void setup() { + Serial.begin(9600); + pinMode(buttonPin, INPUT); +} + +// loop checks the button pin each time, +// and will send serial if it is pressed +void loop() { + if (digitalRead(buttonPin) == HIGH) { + Serial.write('H'); + } + else { + Serial.write('L'); + } + + delay(1000); +} +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Structure/Sketch/setup.adoc b/Language/Structure/Sketch/setup.adoc index 9e101838e..3b46b5523 100644 --- a/Language/Structure/Sketch/setup.adoc +++ b/Language/Structure/Sketch/setup.adoc @@ -1,60 +1,60 @@ ---- -title: setup() -categories: [ "Functions" ] -subCategories: [ "Sketch" ] ---- - - - - - -= setup() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The `setup()` function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The `setup()` function will only run once, after each powerup or reset of the Arduino board. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -int buttonPin = 3; - -void setup() { - Serial.begin(9600); - pinMode(buttonPin, INPUT); -} - -void loop() { - // ... -} ----- - --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - --- -// SEE ALSO SECTION ENDS +--- +title: setup() +categories: [ "Functions" ] +subCategories: [ "Sketch" ] +--- + + + + + += setup() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The `setup()` function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The `setup()` function will only run once, after each powerup or reset of the Arduino board. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +int buttonPin = 3; + +void setup() { + Serial.begin(9600); + pinMode(buttonPin, INPUT); +} + +void loop() { + // ... +} +---- + +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Constants/constants.adoc b/Language/Variables/Constants/constants.adoc index 2271882f9..32650ad60 100644 --- a/Language/Variables/Constants/constants.adoc +++ b/Language/Variables/Constants/constants.adoc @@ -1,131 +1,131 @@ ---- -title: constants -categories: [ "Variables" ] -subCategories: [ "Constants" ] ---- - -= Constants - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -== Description -Constants are predefined expressions in the Arduino language. They are used to make the programs easier to read. We classify constants in groups: - -[float] -== Defining Logical Levels: true and false (Boolean Constants) -There are two constants used to represent truth and falsity in the Arduino language: `true`, and `false`. - -[float] -=== false -`false` is the easier of the two to define. false is defined as 0 (zero). -[%hardbreaks] - -[float] -=== true -`true` is often said to be defined as 1, which is correct, but true has a wider definition. Any integer which is non-zero is true, in a Boolean sense. So -1, 2 and -200 are all defined as true, too, in a Boolean sense. -[%hardbreaks] - -Note that the `true` and `false` constants are typed in lowercase unlike `HIGH`, `LOW`, `INPUT`, and `OUTPUT`. -[%hardbreaks] - -[float] -== Defining Pin Levels: HIGH and LOW -When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: `HIGH` and `LOW`. - -[float] -=== HIGH -The meaning of `HIGH` (in reference to a pin) is somewhat different depending on whether a pin is set to an `INPUT` or `OUTPUT`. When a pin is configured as an `INPUT` with link:../../../functions/digital-io/pinmode[pinMode()], and read with link:../../../functions/digital-io/digitalread[digitalRead()], the Arduino (ATmega) will report `HIGH` if: - - - a voltage greater than 3.0V is present at the pin (5V boards) - - a voltage greater than 2.0V volts is present at the pin (3.3V boards) -[%hardbreaks] - -A pin may also be configured as an INPUT with `pinMode()`, and subsequently made HIGH with link:../../../functions/digital-io/digitalwrite[digitalWrite()]. This will enable the internal 20K pullup resistors, which will _pull up_ the input pin to a `HIGH` reading unless it is pulled `LOW` by external circuitry. This can done alternatively by passing `INPUT_PULLUP` as argument to the `pinMode()` funtion, as explained in more detail in the section "Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT" further below. -[%hardbreaks] - -When a pin is configured to OUTPUT with `pinMode()`, and set to `HIGH` with `digitalWrite()`, the pin is at: - - - 5 volts (5V boards) - - 3.3 volts (3.3V boards) - -In this state it can source current, e.g. light an LED that is connected through a series resistor to ground. -[%hardbreaks] - -[float] -=== LOW -The meaning of `LOW` also has a different meaning depending on whether a pin is set to `INPUT` or `OUTPUT`. When a pin is configured as an `INPUT` with `pinMode()`, and read with `digitalRead()`, the Arduino (ATmega) will report LOW if: - - - a voltage less than 1.5V is present at the pin (5V boards) - - a voltage less than 1.0V (Approx) is present at the pin (3.3V boards) - -When a pin is configured to `OUTPUT` with `pinMode()`, and set to `LOW` with `digitalWrite()`, the pin is at 0 volts (both 5V and 3.3V boards). In this state it can sink current, e.g. light an LED that is connected through a series resistor to +5 volts (or +3.3 volts). -[%hardbreaks] - -[float] -== Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT -Digital pins can be used as `INPUT`, `INPUT_PULLUP`, or `OUTPUT`. Changing a pin with `pinMode()` changes the electrical behavior of the pin. - -[float] -=== Pins Configured as INPUT -Arduino (ATmega) pins configured as `INPUT` with `pinMode()` are said to be in a _high-impedance_ state. Pins configured as `INPUT` make extremely small demands on the circuit that they are sampling, equivalent to a series resistor of 100 Megohms in front of the pin. This makes them useful for reading a sensor. -[%hardbreaks] - -If you have your pin configured as an `INPUT`, and are reading a switch, when the switch is in the open state the input pin will be "floating", resulting in unpredictable results. In order to assure a proper reading when the switch is open, a pull-up or pull-down resistor must be used. The purpose of this resistor is to pull the pin to a known state when the switch is open. A 10 K ohm resistor is usually chosen, as it is a low enough value to reliably prevent a floating input, and at the same time a high enough value to not not draw too much current when the switch is closed. See the http://arduino.cc/en/Tutorial/DigitalReadSerial[Digital Read Serial^] tutorial for more information. -[%hardbreaks] - -If a pull-down resistor is used, the input pin will be `LOW` when the switch is open and `HIGH` when the switch is closed. -[%hardbreaks] - -If a pull-up resistor is used, the input pin will be `HIGH` when the switch is open and `LOW` when the switch is closed. -[%hardbreaks] - -[float] -=== Pins Configured as INPUT_PULLUP -The ATmega microcontroller on the Arduino has internal pull-up resistors (resistors that connect to power internally) that you can access. If you prefer to use these instead of external pull-up resistors, you can use the `INPUT_PULLUP` argument in `pinMode()`. -[%hardbreaks] - -See the http://arduino.cc/en/Tutorial/InputPullupSerial[Input Pullup Serial^] tutorial for an example of this in use. -[%hardbreaks] - -Pins configured as inputs with either `INPUT` or `INPUT_PULLUP` can be damaged or destroyed if they are connected to voltages below ground (negative voltages) or above the positive power rail (5V or 3V). -[%hardbreaks] - -[float] -=== Pins Configured as OUTPUT -Pins configured as `OUTPUT` with `pinMode()` are said to be in a _low-impedance_ state. This means that they can provide a substantial amount of current to other circuits. ATmega pins can source (provide current) or sink (absorb current) up to 40 mA (milliamps) of current to other devices/circuits. This makes them useful for powering LEDs because LEDs typically use less than 40 mA. Loads greater than 40 mA (e.g. motors) will require a transistor or other interface circuitry. -[%hardbreaks] - -Pins configured as outputs can be damaged or destroyed if they are connected to either the ground or positive power rails. -[%hardbreaks] - -[float] -== Defining built-ins: LED_BUILTIN -Most Arduino boards have a pin connected to an on-board LED in series with a resistor. The constant `LED_BUILTIN` is the number of the pin to which the on-board LED is connected. Most boards have this LED connected to digital pin 13. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - --- -// HOW TO USE SECTION ENDS - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: constants +categories: [ "Variables" ] +subCategories: [ "Constants" ] +--- + += Constants + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +== Description +Constants are predefined expressions in the Arduino language. They are used to make the programs easier to read. We classify constants in groups: + +[float] +== Defining Logical Levels: true and false (Boolean Constants) +There are two constants used to represent truth and falsity in the Arduino language: `true`, and `false`. + +[float] +=== false +`false` is the easier of the two to define. false is defined as 0 (zero). +[%hardbreaks] + +[float] +=== true +`true` is often said to be defined as 1, which is correct, but true has a wider definition. Any integer which is non-zero is true, in a Boolean sense. So -1, 2 and -200 are all defined as true, too, in a Boolean sense. +[%hardbreaks] + +Note that the `true` and `false` constants are typed in lowercase unlike `HIGH`, `LOW`, `INPUT`, and `OUTPUT`. +[%hardbreaks] + +[float] +== Defining Pin Levels: HIGH and LOW +When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: `HIGH` and `LOW`. + +[float] +=== HIGH +The meaning of `HIGH` (in reference to a pin) is somewhat different depending on whether a pin is set to an `INPUT` or `OUTPUT`. When a pin is configured as an `INPUT` with link:../../../functions/digital-io/pinmode[pinMode()], and read with link:../../../functions/digital-io/digitalread[digitalRead()], the Arduino (ATmega) will report `HIGH` if: + + - a voltage greater than 3.0V is present at the pin (5V boards) + - a voltage greater than 2.0V volts is present at the pin (3.3V boards) +[%hardbreaks] + +A pin may also be configured as an INPUT with `pinMode()`, and subsequently made HIGH with link:../../../functions/digital-io/digitalwrite[digitalWrite()]. This will enable the internal 20K pullup resistors, which will _pull up_ the input pin to a `HIGH` reading unless it is pulled `LOW` by external circuitry. This can done alternatively by passing `INPUT_PULLUP` as argument to the `pinMode()` funtion, as explained in more detail in the section "Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT" further below. +[%hardbreaks] + +When a pin is configured to OUTPUT with `pinMode()`, and set to `HIGH` with `digitalWrite()`, the pin is at: + + - 5 volts (5V boards) + - 3.3 volts (3.3V boards) + +In this state it can source current, e.g. light an LED that is connected through a series resistor to ground. +[%hardbreaks] + +[float] +=== LOW +The meaning of `LOW` also has a different meaning depending on whether a pin is set to `INPUT` or `OUTPUT`. When a pin is configured as an `INPUT` with `pinMode()`, and read with `digitalRead()`, the Arduino (ATmega) will report LOW if: + + - a voltage less than 1.5V is present at the pin (5V boards) + - a voltage less than 1.0V (Approx) is present at the pin (3.3V boards) + +When a pin is configured to `OUTPUT` with `pinMode()`, and set to `LOW` with `digitalWrite()`, the pin is at 0 volts (both 5V and 3.3V boards). In this state it can sink current, e.g. light an LED that is connected through a series resistor to +5 volts (or +3.3 volts). +[%hardbreaks] + +[float] +== Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT +Digital pins can be used as `INPUT`, `INPUT_PULLUP`, or `OUTPUT`. Changing a pin with `pinMode()` changes the electrical behavior of the pin. + +[float] +=== Pins Configured as INPUT +Arduino (ATmega) pins configured as `INPUT` with `pinMode()` are said to be in a _high-impedance_ state. Pins configured as `INPUT` make extremely small demands on the circuit that they are sampling, equivalent to a series resistor of 100 Megohms in front of the pin. This makes them useful for reading a sensor. +[%hardbreaks] + +If you have your pin configured as an `INPUT`, and are reading a switch, when the switch is in the open state the input pin will be "floating", resulting in unpredictable results. In order to assure a proper reading when the switch is open, a pull-up or pull-down resistor must be used. The purpose of this resistor is to pull the pin to a known state when the switch is open. A 10 K ohm resistor is usually chosen, as it is a low enough value to reliably prevent a floating input, and at the same time a high enough value to not not draw too much current when the switch is closed. See the http://arduino.cc/en/Tutorial/DigitalReadSerial[Digital Read Serial^] tutorial for more information. +[%hardbreaks] + +If a pull-down resistor is used, the input pin will be `LOW` when the switch is open and `HIGH` when the switch is closed. +[%hardbreaks] + +If a pull-up resistor is used, the input pin will be `HIGH` when the switch is open and `LOW` when the switch is closed. +[%hardbreaks] + +[float] +=== Pins Configured as INPUT_PULLUP +The ATmega microcontroller on the Arduino has internal pull-up resistors (resistors that connect to power internally) that you can access. If you prefer to use these instead of external pull-up resistors, you can use the `INPUT_PULLUP` argument in `pinMode()`. +[%hardbreaks] + +See the http://arduino.cc/en/Tutorial/InputPullupSerial[Input Pullup Serial^] tutorial for an example of this in use. +[%hardbreaks] + +Pins configured as inputs with either `INPUT` or `INPUT_PULLUP` can be damaged or destroyed if they are connected to voltages below ground (negative voltages) or above the positive power rail (5V or 3V). +[%hardbreaks] + +[float] +=== Pins Configured as OUTPUT +Pins configured as `OUTPUT` with `pinMode()` are said to be in a _low-impedance_ state. This means that they can provide a substantial amount of current to other circuits. ATmega pins can source (provide current) or sink (absorb current) up to 40 mA (milliamps) of current to other devices/circuits. This makes them useful for powering LEDs because LEDs typically use less than 40 mA. Loads greater than 40 mA (e.g. motors) will require a transistor or other interface circuitry. +[%hardbreaks] + +Pins configured as outputs can be damaged or destroyed if they are connected to either the ground or positive power rails. +[%hardbreaks] + +[float] +== Defining built-ins: LED_BUILTIN +Most Arduino boards have a pin connected to an on-board LED in series with a resistor. The constant `LED_BUILTIN` is the number of the pin to which the on-board LED is connected. Most boards have this LED connected to digital pin 13. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +-- +// HOW TO USE SECTION ENDS + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Constants/floatingPointConstants.adoc b/Language/Variables/Constants/floatingPointConstants.adoc index b595af718..43e248203 100644 --- a/Language/Variables/Constants/floatingPointConstants.adoc +++ b/Language/Variables/Constants/floatingPointConstants.adoc @@ -1,80 +1,80 @@ ---- -title: Floating Point Constants -categories: [ "Variables" ] -subCategories: [ "Constants" ] ---- - - - - - -= Floating Point Constants - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Similar to integer constants, floating point constants are used to make code more readable. Floating point constants are swapped at compile time for the value to which the expression evaluates. -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -n = 0.005; // 0.005 is a floating point constant ----- -[%hardbreaks] - -[float] -=== Notes and Warnings -Floating point constants can also be expressed in a variety of scientific notation. 'E' and 'e' are both accepted as valid exponent indicators. -[%hardbreaks] - -|=== -|floating-point constant |evaluates to: |also evaluates to: - -|10.0 -|10 -| - -|2.34E5 -|2.34 * 10^5 -|234000 - -|67e-12 -|67.0 * 10^-12 -|0.000000000067 - -|=== -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: Floating Point Constants +categories: [ "Variables" ] +subCategories: [ "Constants" ] +--- + + + + + += Floating Point Constants + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Similar to integer constants, floating point constants are used to make code more readable. Floating point constants are swapped at compile time for the value to which the expression evaluates. +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +n = 0.005; // 0.005 is a floating point constant +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +Floating point constants can also be expressed in a variety of scientific notation. 'E' and 'e' are both accepted as valid exponent indicators. +[%hardbreaks] + +|=== +|floating-point constant |evaluates to: |also evaluates to: + +|10.0 +|10 +| + +|2.34E5 +|2.34 * 10^5 +|234000 + +|67e-12 +|67.0 * 10^-12 +|0.000000000067 + +|=== +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Constants/integerConstants.adoc b/Language/Variables/Constants/integerConstants.adoc index c7ad5bada..d34e50370 100644 --- a/Language/Variables/Constants/integerConstants.adoc +++ b/Language/Variables/Constants/integerConstants.adoc @@ -1,143 +1,143 @@ ---- -title: Integer Constants -categories: [ "Variables" ] -subCategories: [ "Constants" ] ---- - - - - - -= Integer Constants - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Integer constants are numbers that are used directly in a sketch, like 123. By default, these numbers are treated as link:../../data-types/int[int] but you can change this with the U and L modifiers (see below). -[%hardbreaks] - -Normally, integer constants are treated as base 10 (decimal) integers, but special notation (formatters) may be used to enter numbers in other bases. -[%hardbreaks] - -|=== -|Base |Example |Formatter |Comment - -|10 (decimal) -|123 -|none -| - -|2 (binary) -|B1111011 -|leading 'B' -|only works with 8 bit values (0 to 255) characters 0&1 valid - -|8 (octal) -|0173 -|leading "0" -|characters 0-7 valid - -|16 (hexadecimal) -|0x7B -|leading "0x" -|characters 0-9, A-F, a-f valid -|=== -[%hardbreaks] - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- -[float] -== Decimal (base 10) -This is the common-sense math with which you are acquainted. Constants without other prefixes are assumed to be in decimal format. - -[float] -=== Example Code: -[source,arduino] ----- -n = 101; // same as 101 decimal ((1 * 10^2) + (0 * 10^1) + 1) ----- -[%hardbreaks] - -[float] -== Binary (base 2) -Only the characters 0 and 1 are valid. - -[float] -=== Example Code: -[source,arduino] ----- -n = B101; // same as 5 decimal ((1 * 2^2) + (0 * 2^1) + 1) ----- - -The binary formatter only works on bytes (8 bits) between 0 (B0) and 255 (B11111111). If it is convenient to input an int (16 bits) in binary form you can do it a two-step procedure such as: -[source,arduino] ----- -myInt = (B11001100 * 256) + B10101010; // B11001100 is the high byte` ----- -[%hardbreaks] - -[float] -== Octal (base 8) -Only the characters 0 through 7 are valid. Octal values are indicated by the prefix "0" (zero). - -[float] -=== Example Code: -[source,arduino] ----- -n = 0101; // same as 65 decimal ((1 * 8^2) + (0 * 8^1) + 1) ----- -It is possible to generate a hard-to-find bug by (unintentionally) including a leading zero before a constant and having the compiler unintentionally interpret your constant as octal. -[%hardbreaks] - -[float] -== Hexadecimal (base 16) -Valid characters are 0 through 9 and letters A through F; A has the value 10, B is 11, up to F, which is 15. Hex values are indicated by the prefix "0x". Note that A-F may be upper (A-F) or lower case (a-f). - -[float] -=== Example Code: -[source,arduino] ----- -n = 0x101; // same as 257 decimal ((1 * 16^2) + (0 * 16^1) + 1) ----- -[%hardbreaks] - - -[float] -=== Notes and Warnings -*U & L formatters:* - -By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with: - - - a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u - - a 'l' or 'L' to force the constant into a long data format. Example: 100000L - - a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul - -[%hardbreaks] - --- -// HOW TO USE SECTION ENDS - - - - -// SEE ALSO SECTION BEGINS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: Integer Constants +categories: [ "Variables" ] +subCategories: [ "Constants" ] +--- + + + + + += Integer Constants + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Integer constants are numbers that are used directly in a sketch, like 123. By default, these numbers are treated as link:../../data-types/int[int] but you can change this with the U and L modifiers (see below). +[%hardbreaks] + +Normally, integer constants are treated as base 10 (decimal) integers, but special notation (formatters) may be used to enter numbers in other bases. +[%hardbreaks] + +|=== +|Base |Example |Formatter |Comment + +|10 (decimal) +|123 +|none +| + +|2 (binary) +|B1111011 +|leading 'B' +|only works with 8 bit values (0 to 255) characters 0&1 valid + +|8 (octal) +|0173 +|leading "0" +|characters 0-7 valid + +|16 (hexadecimal) +|0x7B +|leading "0x" +|characters 0-9, A-F, a-f valid +|=== +[%hardbreaks] + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- +[float] +== Decimal (base 10) +This is the common-sense math with which you are acquainted. Constants without other prefixes are assumed to be in decimal format. + +[float] +=== Example Code: +[source,arduino] +---- +n = 101; // same as 101 decimal ((1 * 10^2) + (0 * 10^1) + 1) +---- +[%hardbreaks] + +[float] +== Binary (base 2) +Only the characters 0 and 1 are valid. + +[float] +=== Example Code: +[source,arduino] +---- +n = B101; // same as 5 decimal ((1 * 2^2) + (0 * 2^1) + 1) +---- + +The binary formatter only works on bytes (8 bits) between 0 (B0) and 255 (B11111111). If it is convenient to input an int (16 bits) in binary form you can do it a two-step procedure such as: +[source,arduino] +---- +myInt = (B11001100 * 256) + B10101010; // B11001100 is the high byte` +---- +[%hardbreaks] + +[float] +== Octal (base 8) +Only the characters 0 through 7 are valid. Octal values are indicated by the prefix "0" (zero). + +[float] +=== Example Code: +[source,arduino] +---- +n = 0101; // same as 65 decimal ((1 * 8^2) + (0 * 8^1) + 1) +---- +It is possible to generate a hard-to-find bug by (unintentionally) including a leading zero before a constant and having the compiler unintentionally interpret your constant as octal. +[%hardbreaks] + +[float] +== Hexadecimal (base 16) +Valid characters are 0 through 9 and letters A through F; A has the value 10, B is 11, up to F, which is 15. Hex values are indicated by the prefix "0x". Note that A-F may be upper (A-F) or lower case (a-f). + +[float] +=== Example Code: +[source,arduino] +---- +n = 0x101; // same as 257 decimal ((1 * 16^2) + (0 * 16^1) + 1) +---- +[%hardbreaks] + + +[float] +=== Notes and Warnings +*U & L formatters:* + +By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with: + + - a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u + - a 'l' or 'L' to force the constant into a long data format. Example: 100000L + - a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul + +[%hardbreaks] + +-- +// HOW TO USE SECTION ENDS + + + + +// SEE ALSO SECTION BEGINS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/c_str.adoc b/Language/Variables/Data Types/String/Functions/c_str.adoc index 24ec2e491..825f61e06 100644 --- a/Language/Variables/Data Types/String/Functions/c_str.adoc +++ b/Language/Variables/Data Types/String/Functions/c_str.adoc @@ -1,57 +1,57 @@ ---- -title: "c_str()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= c_str() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Converts the contents of a String as a C-style, null-terminated string. Note that this gives direct access to the internal String buffer and should be used with care. In particular, you should never modify the string through the pointer returned. When you modify the String object, or when it is destroyed, any pointer previously returned by c_str() becomes invalid and should not be used any longer. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.c_str()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -A pointer to the C-style version of the invoking String. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "c_str()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += c_str() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts the contents of a String as a C-style, null-terminated string. Note that this gives direct access to the internal String buffer and should be used with care. In particular, you should never modify the string through the pointer returned. When you modify the String object, or when it is destroyed, any pointer previously returned by c_str() becomes invalid and should not be used any longer. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.c_str()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +A pointer to the C-style version of the invoking String. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/charAt.adoc b/Language/Variables/Data Types/String/Functions/charAt.adoc index 1db376bb6..a546ddd01 100644 --- a/Language/Variables/Data Types/String/Functions/charAt.adoc +++ b/Language/Variables/Data Types/String/Functions/charAt.adoc @@ -1,58 +1,58 @@ ---- -title: "charAt()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= charAt() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Access a particular character of the String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.charAt(n)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`n`: a variable. Allowed data types: `unsigned int`. - - -[float] -=== Returns -The n'th character of the String. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "charAt()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += charAt() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Access a particular character of the String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.charAt(n)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`n`: a variable. Allowed data types: `unsigned int`. + + +[float] +=== Returns +The n'th character of the String. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/compareTo.adoc b/Language/Variables/Data Types/String/Functions/compareTo.adoc index 98149180f..e03885872 100644 --- a/Language/Variables/Data Types/String/Functions/compareTo.adoc +++ b/Language/Variables/Data Types/String/Functions/compareTo.adoc @@ -1,61 +1,61 @@ ---- -title: "compareTo()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= compareTo() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Compares two Strings, testing whether one comes before or after the other, or whether they're equal. The strings are compared character by character, using the ASCII values of the characters. That means, for example, that 'a' comes before 'b' but after 'A'. Numbers come before letters. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.compareTo(myString2)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`myString2`: another variable of type `String`. - - -[float] -=== Returns -`a negative number`: if myString comes before myString2. + -`0`: if String equals myString2. + -`a positive number`: if myString comes after myString2. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "compareTo()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += compareTo() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Compares two Strings, testing whether one comes before or after the other, or whether they're equal. The strings are compared character by character, using the ASCII values of the characters. That means, for example, that 'a' comes before 'b' but after 'A'. Numbers come before letters. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.compareTo(myString2)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`myString2`: another variable of type `String`. + + +[float] +=== Returns +`a negative number`: if myString comes before myString2. + +`0`: if String equals myString2. + +`a positive number`: if myString comes after myString2. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/concat.adoc b/Language/Variables/Data Types/String/Functions/concat.adoc index 6161f6a9a..95c35f550 100644 --- a/Language/Variables/Data Types/String/Functions/concat.adoc +++ b/Language/Variables/Data Types/String/Functions/concat.adoc @@ -1,59 +1,59 @@ ---- -title: "concat()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= concat() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Appends the parameter to a String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.concat(parameter)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`parameter`: Allowed data types: `String`, `string`, `char`, `byte`, `int`, `unsigned int`, `long`, `unsigned long`, `float`, `double`, `__FlashStringHelper`(`F()` macro). - - -[float] -=== Returns -`true`: success. + -`false`: failure (in which case the String is left unchanged). - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "concat()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += concat() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Appends the parameter to a String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.concat(parameter)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`parameter`: Allowed data types: `String`, `string`, `char`, `byte`, `int`, `unsigned int`, `long`, `unsigned long`, `float`, `double`, `__FlashStringHelper`(`F()` macro). + + +[float] +=== Returns +`true`: success. + +`false`: failure (in which case the String is left unchanged). + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/endsWith.adoc b/Language/Variables/Data Types/String/Functions/endsWith.adoc index 02d5b07fa..7b456df76 100644 --- a/Language/Variables/Data Types/String/Functions/endsWith.adoc +++ b/Language/Variables/Data Types/String/Functions/endsWith.adoc @@ -1,59 +1,59 @@ ---- -title: "endsWith()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= endsWith() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Tests whether or not a String ends with the characters of another String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.endsWith(myString2)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`myString2`: another variable of type `String`. - - -[float] -=== Returns -`true`: if myString ends with the characters of myString2. + -`false`: otherwise. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "endsWith()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += endsWith() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Tests whether or not a String ends with the characters of another String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.endsWith(myString2)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`myString2`: another variable of type `String`. + + +[float] +=== Returns +`true`: if myString ends with the characters of myString2. + +`false`: otherwise. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/equals.adoc b/Language/Variables/Data Types/String/Functions/equals.adoc index c784f2f81..2de11b4ea 100644 --- a/Language/Variables/Data Types/String/Functions/equals.adoc +++ b/Language/Variables/Data Types/String/Functions/equals.adoc @@ -1,58 +1,58 @@ ---- -title: "equals()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= equals() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Compares two Strings for equality. The comparison is case-sensitive, meaning the String "hello" is not equal to the String "HELLO". - -[%hardbreaks] - - -[float] -=== Syntax -`myString.equals(myString2)` - - -[float] -=== Parameters -`myString, myString2`: variables of type `String`. - - -[float] -=== Returns -`true`: if string equals string2. + -`false`: otherwise. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "equals()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += equals() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Compares two Strings for equality. The comparison is case-sensitive, meaning the String "hello" is not equal to the String "HELLO". + +[%hardbreaks] + + +[float] +=== Syntax +`myString.equals(myString2)` + + +[float] +=== Parameters +`myString, myString2`: variables of type `String`. + + +[float] +=== Returns +`true`: if string equals string2. + +`false`: otherwise. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/equalsIgnoreCase.adoc b/Language/Variables/Data Types/String/Functions/equalsIgnoreCase.adoc index 76c8ba689..d95953703 100644 --- a/Language/Variables/Data Types/String/Functions/equalsIgnoreCase.adoc +++ b/Language/Variables/Data Types/String/Functions/equalsIgnoreCase.adoc @@ -1,59 +1,59 @@ ---- -title: "equalsIgnoreCase()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= equalsIgnoreCase() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Compares two Strings for equality. The comparison is not case-sensitive, meaning the String("hello") is equal to the String("HELLO"). - -[%hardbreaks] - - -[float] -=== Syntax -`myString.equalsIgnoreCase(myString2)` - - -[float] -=== Parameters -`myString`: variable of type `String`. + -`myString2`: variable of type `String`. - - -[float] -=== Returns -`true`: if myString equals myString2 (ignoring case). + -`false`: otherwise. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "equalsIgnoreCase()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += equalsIgnoreCase() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Compares two Strings for equality. The comparison is not case-sensitive, meaning the String("hello") is equal to the String("HELLO"). + +[%hardbreaks] + + +[float] +=== Syntax +`myString.equalsIgnoreCase(myString2)` + + +[float] +=== Parameters +`myString`: variable of type `String`. + +`myString2`: variable of type `String`. + + +[float] +=== Returns +`true`: if myString equals myString2 (ignoring case). + +`false`: otherwise. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/getBytes.adoc b/Language/Variables/Data Types/String/Functions/getBytes.adoc index 7019ba3a3..ac758819e 100644 --- a/Language/Variables/Data Types/String/Functions/getBytes.adoc +++ b/Language/Variables/Data Types/String/Functions/getBytes.adoc @@ -1,59 +1,59 @@ ---- -title: "getBytes()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= getBytes() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Copies the String's characters to the supplied buffer. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.getBytes(buf, len)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`buf`: the buffer to copy the characters into. Allowed data types: array of `byte`s. + -`len`: the size of the buffer. Allowed data types: `unsigned int`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "getBytes()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += getBytes() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Copies the String's characters to the supplied buffer. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.getBytes(buf, len)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`buf`: the buffer to copy the characters into. Allowed data types: array of `byte`s. + +`len`: the size of the buffer. Allowed data types: `unsigned int`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/indexOf.adoc b/Language/Variables/Data Types/String/Functions/indexOf.adoc index aaba45ffc..58df9db78 100644 --- a/Language/Variables/Data Types/String/Functions/indexOf.adoc +++ b/Language/Variables/Data Types/String/Functions/indexOf.adoc @@ -1,61 +1,61 @@ ---- -title: "indexOf()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= indexOf() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Locates a character or String within another String. By default, searches from the beginning of the String, but can also start from a given index, allowing for the locating of all instances of the character or String. - - -[%hardbreaks] - - -[float] -=== Syntax -`myString.indexOf(val)` + -`myString.indexOf(val, from)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`val`: the value to search for. Allowed data types: `char`, `String`. + -`from`: the index to start the search from. - - -[float] -=== Returns -The index of val within the String, or -1 if not found. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "indexOf()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += indexOf() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Locates a character or String within another String. By default, searches from the beginning of the String, but can also start from a given index, allowing for the locating of all instances of the character or String. + + +[%hardbreaks] + + +[float] +=== Syntax +`myString.indexOf(val)` + +`myString.indexOf(val, from)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`val`: the value to search for. Allowed data types: `char`, `String`. + +`from`: the index to start the search from. + + +[float] +=== Returns +The index of val within the String, or -1 if not found. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/lastIndexOf.adoc b/Language/Variables/Data Types/String/Functions/lastIndexOf.adoc index 1a6700532..ffabd6589 100644 --- a/Language/Variables/Data Types/String/Functions/lastIndexOf.adoc +++ b/Language/Variables/Data Types/String/Functions/lastIndexOf.adoc @@ -1,60 +1,60 @@ ---- -title: "lastIndexOf()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= lastIndexOf() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Locates a character or String within another String. By default, searches from the end of the String, but can also work backwards from a given index, allowing for the locating of all instances of the character or String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.lastIndexOf(val)` + -`myString.lastIndexOf(val, from)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`val`: the value to search for. Allowed data types: `char`, `String`. + -`from`: the index to work backwards from. - - -[float] -=== Returns -The index of val within the String, or -1 if not found. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "lastIndexOf()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += lastIndexOf() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Locates a character or String within another String. By default, searches from the end of the String, but can also work backwards from a given index, allowing for the locating of all instances of the character or String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.lastIndexOf(val)` + +`myString.lastIndexOf(val, from)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`val`: the value to search for. Allowed data types: `char`, `String`. + +`from`: the index to work backwards from. + + +[float] +=== Returns +The index of val within the String, or -1 if not found. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/length.adoc b/Language/Variables/Data Types/String/Functions/length.adoc index d0a2703e6..a0b644b42 100644 --- a/Language/Variables/Data Types/String/Functions/length.adoc +++ b/Language/Variables/Data Types/String/Functions/length.adoc @@ -1,57 +1,57 @@ ---- -title: "length()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= length() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Returns the length of the String, in characters. (Note that this doesn't include a trailing null character.) - -[%hardbreaks] - - -[float] -=== Syntax -`myString.length()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -The length of the String in characters. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "length()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += length() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Returns the length of the String, in characters. (Note that this doesn't include a trailing null character.) + +[%hardbreaks] + + +[float] +=== Syntax +`myString.length()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +The length of the String in characters. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/remove.adoc b/Language/Variables/Data Types/String/Functions/remove.adoc index 02ea6a7a7..55b419ed1 100644 --- a/Language/Variables/Data Types/String/Functions/remove.adoc +++ b/Language/Variables/Data Types/String/Functions/remove.adoc @@ -1,73 +1,73 @@ ---- -title: "remove()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= remove() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Modify in place a String removing chars from the provided index to the end of the String or from the provided index to index plus count. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.remove(index)` + -`myString.remove(index, count)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`index`: The position at which to start the remove process (zero indexed). Allowed data types: `unsigned int`. + -`count`: The number of characters to remove. Allowed data types: `unsigned int`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ -[source,arduino] ----- -String greeting = "hello"; -greeting.remove(2, 2); // greeting now contains "heo" ----- -[%hardbreaks] --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "remove()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += remove() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Modify in place a String removing chars from the provided index to the end of the String or from the provided index to index plus count. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.remove(index)` + +`myString.remove(index, count)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`index`: The position at which to start the remove process (zero indexed). Allowed data types: `unsigned int`. + +`count`: The number of characters to remove. Allowed data types: `unsigned int`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ +[source,arduino] +---- +String greeting = "hello"; +greeting.remove(2, 2); // greeting now contains "heo" +---- +[%hardbreaks] +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/replace.adoc b/Language/Variables/Data Types/String/Functions/replace.adoc index 0905a7d5d..2555182a2 100644 --- a/Language/Variables/Data Types/String/Functions/replace.adoc +++ b/Language/Variables/Data Types/String/Functions/replace.adoc @@ -1,59 +1,59 @@ ---- -title: "replace()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= replace() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The String replace() function allows you to replace all instances of a given character with another character. You can also use replace to replace substrings of a String with a different substring. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.replace(substring1, substring2)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`substring1`: another variable of type `String`. + -`substring2`: another variable of type `String`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "replace()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += replace() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The String replace() function allows you to replace all instances of a given character with another character. You can also use replace to replace substrings of a String with a different substring. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.replace(substring1, substring2)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`substring1`: another variable of type `String`. + +`substring2`: another variable of type `String`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/reserve.adoc b/Language/Variables/Data Types/String/Functions/reserve.adoc index ee679674c..10d76d6ec 100644 --- a/Language/Variables/Data Types/String/Functions/reserve.adoc +++ b/Language/Variables/Data Types/String/Functions/reserve.adoc @@ -1,88 +1,88 @@ ---- -title: "reserve()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= reserve() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -The String reserve() function allows you to allocate a buffer in memory for manipulating Strings. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.reserve(size)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`size`: the number of bytes in memory to save for String manipulation. Allowed data types: `unsigned int`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code - -[source,arduino] ----- -String myString; - -void setup() { - // initialize serial and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB - } - - myString.reserve(26); - myString = "i="; - myString += "1234"; - myString += ", is that ok?"; - - // print the String: - Serial.println(myString); -} - -void loop() { - // nothing to do here -} ----- --- -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "reserve()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += reserve() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +The String reserve() function allows you to allocate a buffer in memory for manipulating Strings. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.reserve(size)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`size`: the number of bytes in memory to save for String manipulation. Allowed data types: `unsigned int`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code + +[source,arduino] +---- +String myString; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB + } + + myString.reserve(26); + myString = "i="; + myString += "1234"; + myString += ", is that ok?"; + + // print the String: + Serial.println(myString); +} + +void loop() { + // nothing to do here +} +---- +-- +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/setCharAt.adoc b/Language/Variables/Data Types/String/Functions/setCharAt.adoc index d0dfc823a..369126e44 100644 --- a/Language/Variables/Data Types/String/Functions/setCharAt.adoc +++ b/Language/Variables/Data Types/String/Functions/setCharAt.adoc @@ -1,59 +1,59 @@ ---- -title: "setCharAt()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= setCharAt() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Sets a character of the String. Has no effect on indices outside the existing length of the String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.setCharAt(index, c)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`index`: the index to set the character at. + -`c`: the character to store to the given location. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "setCharAt()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += setCharAt() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Sets a character of the String. Has no effect on indices outside the existing length of the String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.setCharAt(index, c)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`index`: the index to set the character at. + +`c`: the character to store to the given location. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/startsWith.adoc b/Language/Variables/Data Types/String/Functions/startsWith.adoc index 76390ac91..3cf1acf7b 100644 --- a/Language/Variables/Data Types/String/Functions/startsWith.adoc +++ b/Language/Variables/Data Types/String/Functions/startsWith.adoc @@ -1,58 +1,58 @@ ---- -title: "startsWith()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= startsWith() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Tests whether or not a String starts with the characters of another String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.startsWith(myString2)` - - -[float] -=== Parameters -`myString, myString2`: a variable of type `String`. - - -[float] -=== Returns -`true`: if myString starts with the characters of myString2. + -`false`: otherwise - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "startsWith()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += startsWith() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Tests whether or not a String starts with the characters of another String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.startsWith(myString2)` + + +[float] +=== Parameters +`myString, myString2`: a variable of type `String`. + + +[float] +=== Returns +`true`: if myString starts with the characters of myString2. + +`false`: otherwise + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/substring.adoc b/Language/Variables/Data Types/String/Functions/substring.adoc index 5cf91d596..cee035575 100644 --- a/Language/Variables/Data Types/String/Functions/substring.adoc +++ b/Language/Variables/Data Types/String/Functions/substring.adoc @@ -1,60 +1,60 @@ ---- -title: "substring()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= substring() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Get a substring of a String. The starting index is inclusive (the corresponding character is included in the substring), but the optional ending index is exclusive (the corresponding character is not included in the substring). If the ending index is omitted, the substring continues to the end of the String. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.substring(from)` + -`myString.substring(from, to)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`from`: the index to start the substring at. + -`to` (optional): the index to end the substring before. - - -[float] -=== Returns -The substring. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "substring()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += substring() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Get a substring of a String. The starting index is inclusive (the corresponding character is included in the substring), but the optional ending index is exclusive (the corresponding character is not included in the substring). If the ending index is omitted, the substring continues to the end of the String. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.substring(from)` + +`myString.substring(from, to)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`from`: the index to start the substring at. + +`to` (optional): the index to end the substring before. + + +[float] +=== Returns +The substring. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/toCharArray.adoc b/Language/Variables/Data Types/String/Functions/toCharArray.adoc index bc36e4c19..c0c24ace6 100644 --- a/Language/Variables/Data Types/String/Functions/toCharArray.adoc +++ b/Language/Variables/Data Types/String/Functions/toCharArray.adoc @@ -1,59 +1,59 @@ ---- -title: "toCharArray()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= toCharArray() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Copies the String's characters to the supplied buffer. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.toCharArray(buf, len)` - - -[float] -=== Parameters -`myString`: a variable of type `String`. + -`buf`: the buffer to copy the characters into. Allowed data types: array of `char`s. + -`len`: the size of the buffer. Allowed data types: `unsigned int`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "toCharArray()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += toCharArray() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Copies the String's characters to the supplied buffer. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.toCharArray(buf, len)` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + +`buf`: the buffer to copy the characters into. Allowed data types: array of `char`s. + +`len`: the size of the buffer. Allowed data types: `unsigned int`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/toDouble.adoc b/Language/Variables/Data Types/String/Functions/toDouble.adoc index 622211837..1ede4a704 100644 --- a/Language/Variables/Data Types/String/Functions/toDouble.adoc +++ b/Language/Variables/Data Types/String/Functions/toDouble.adoc @@ -1,57 +1,57 @@ ---- -title: "toDouble()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= toDouble() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Converts a valid String to a double. The input String should start with a digit. If the String contains non-digit characters, the function will stop performing the conversion. For example, the Strings "123.45", "123", and "123fish" are converted to 123.45, 123.00, and 123.00 respectively. Note that "123.456" is approximated with 123.46. Note too that floats have only 6-7 decimal digits of precision and that longer Strings might be truncated. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.toDouble()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -If no valid conversion could be performed because the String doesn't start with a digit, a zero is returned. Data type: `double`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "toDouble()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += toDouble() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a valid String to a double. The input String should start with a digit. If the String contains non-digit characters, the function will stop performing the conversion. For example, the Strings "123.45", "123", and "123fish" are converted to 123.45, 123.00, and 123.00 respectively. Note that "123.456" is approximated with 123.46. Note too that floats have only 6-7 decimal digits of precision and that longer Strings might be truncated. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.toDouble()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +If no valid conversion could be performed because the String doesn't start with a digit, a zero is returned. Data type: `double`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/toFloat.adoc b/Language/Variables/Data Types/String/Functions/toFloat.adoc index 52d3d3f20..91c1e1f5f 100644 --- a/Language/Variables/Data Types/String/Functions/toFloat.adoc +++ b/Language/Variables/Data Types/String/Functions/toFloat.adoc @@ -1,57 +1,57 @@ ---- -title: "toFloat()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= toFloat() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Converts a valid String to a float. The input String should start with a digit. If the String contains non-digit characters, the function will stop performing the conversion. For example, the Strings "123.45", "123", and "123fish" are converted to 123.45, 123.00, and 123.00 respectively. Note that "123.456" is approximated with 123.46. Note too that floats have only 6-7 decimal digits of precision and that longer Strings might be truncated. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.toFloat()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -If no valid conversion could be performed because the String doesn't start with a digit, a zero is returned. Data type: `float`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "toFloat()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += toFloat() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a valid String to a float. The input String should start with a digit. If the String contains non-digit characters, the function will stop performing the conversion. For example, the Strings "123.45", "123", and "123fish" are converted to 123.45, 123.00, and 123.00 respectively. Note that "123.456" is approximated with 123.46. Note too that floats have only 6-7 decimal digits of precision and that longer Strings might be truncated. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.toFloat()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +If no valid conversion could be performed because the String doesn't start with a digit, a zero is returned. Data type: `float`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/toInt.adoc b/Language/Variables/Data Types/String/Functions/toInt.adoc index f50acb697..3c238da57 100644 --- a/Language/Variables/Data Types/String/Functions/toInt.adoc +++ b/Language/Variables/Data Types/String/Functions/toInt.adoc @@ -1,57 +1,57 @@ ---- -title: "toInt()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= toInt() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Converts a valid String to an integer. The input String should start with an integer number. If the String contains non-integer numbers, the function will stop performing the conversion. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.toInt()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -If no valid conversion could be performed because the String doesn't start with a integer number, a zero is returned. Data type: `long`. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "toInt()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += toInt() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Converts a valid String to an integer. The input String should start with an integer number. If the String contains non-integer numbers, the function will stop performing the conversion. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.toInt()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +If no valid conversion could be performed because the String doesn't start with a integer number, a zero is returned. Data type: `long`. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/toLowerCase.adoc b/Language/Variables/Data Types/String/Functions/toLowerCase.adoc index d94279650..9fe9a2fb5 100644 --- a/Language/Variables/Data Types/String/Functions/toLowerCase.adoc +++ b/Language/Variables/Data Types/String/Functions/toLowerCase.adoc @@ -1,57 +1,57 @@ ---- -title: "toLowerCase()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= toLowerCase() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Get a lower-case version of a String. As of 1.0, toLowerCase() modifies the String in place rather than returning a new one. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.toLowerCase()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "toLowerCase()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += toLowerCase() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Get a lower-case version of a String. As of 1.0, toLowerCase() modifies the String in place rather than returning a new one. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.toLowerCase()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/toUpperCase.adoc b/Language/Variables/Data Types/String/Functions/toUpperCase.adoc index 07beae25d..81ef0dd79 100644 --- a/Language/Variables/Data Types/String/Functions/toUpperCase.adoc +++ b/Language/Variables/Data Types/String/Functions/toUpperCase.adoc @@ -1,56 +1,56 @@ ---- -title: "toUpperCase()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= toUpperCase() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Get an upper-case version of a String. As of 1.0, toUpperCase() modifies the String in place rather than returning a new one. -[%hardbreaks] - - -[float] -=== Syntax -`myString.toUpperCase()` - - -[float] -=== Parameters -`myString`: a variable of type `String`. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "toUpperCase()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += toUpperCase() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Get an upper-case version of a String. As of 1.0, toUpperCase() modifies the String in place rather than returning a new one. +[%hardbreaks] + + +[float] +=== Syntax +`myString.toUpperCase()` + + +[float] +=== Parameters +`myString`: a variable of type `String`. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Functions/trim.adoc b/Language/Variables/Data Types/String/Functions/trim.adoc index 4b965dbcc..f5a3fb27d 100644 --- a/Language/Variables/Data Types/String/Functions/trim.adoc +++ b/Language/Variables/Data Types/String/Functions/trim.adoc @@ -1,57 +1,57 @@ ---- -title: "trim()" -categories: [ "Data Types" ] -subCategories: [ "StringObject Function" ] ---- - - - - - -= trim() - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Get a version of the String with any leading and trailing whitespace removed. As of 1.0, trim() modifies the String in place rather than returning a new one. - -[%hardbreaks] - - -[float] -=== Syntax -`myString.trim()` - - -[float] -=== Parameters -`myString`: a variable of type String. - - -[float] -=== Returns -Nothing - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "trim()" +categories: [ "Data Types" ] +subCategories: [ "StringObject Function" ] +--- + + + + + += trim() + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Get a version of the String with any leading and trailing whitespace removed. As of 1.0, trim() modifies the String in place rather than returning a new one. + +[%hardbreaks] + + +[float] +=== Syntax +`myString.trim()` + + +[float] +=== Parameters +`myString`: a variable of type String. + + +[float] +=== Returns +Nothing + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/append.adoc b/Language/Variables/Data Types/String/Operators/append.adoc index 808d8fe5d..b2ca3b289 100644 --- a/Language/Variables/Data Types/String/Operators/append.adoc +++ b/Language/Variables/Data Types/String/Operators/append.adoc @@ -1,59 +1,59 @@ ---- -title: "+=" -title_expanded: append -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - - - - - -= += Append - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -It concatenates Strings with other data. - -[%hardbreaks] - - -[float] -=== Syntax -`myString1 += data` - - -[float] -=== Parameters -`myString1`: a String variable. - - -[float] -=== Returns -Nothing - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "+=" +title_expanded: append +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + + + + + += += Append + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +It concatenates Strings with other data. + +[%hardbreaks] + + +[float] +=== Syntax +`myString1 += data` + + +[float] +=== Parameters +`myString1`: a String variable. + + +[float] +=== Returns +Nothing + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/comparison.adoc b/Language/Variables/Data Types/String/Operators/comparison.adoc index bdd4e1262..4a711375d 100644 --- a/Language/Variables/Data Types/String/Operators/comparison.adoc +++ b/Language/Variables/Data Types/String/Operators/comparison.adoc @@ -1,57 +1,57 @@ ---- -title: "==" -title_expanded: comparison -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - -= == Comparison - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Compares two Strings for equality. The comparison is case-sensitive, meaning the String "hello" is not equal to the String "HELLO". Functionally the same as string.equals() - - -[%hardbreaks] - - -[float] -=== Syntax -`myString1 == myString2` - -[float] -=== Parameters -`myString1`: a String variable. + -`myString2`: a String variable. - - -[float] -=== Returns -`true`: if myString1 equals myString2. + -`false`: otherwise. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "==" +title_expanded: comparison +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + += == Comparison + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Compares two Strings for equality. The comparison is case-sensitive, meaning the String "hello" is not equal to the String "HELLO". Functionally the same as string.equals() + + +[%hardbreaks] + + +[float] +=== Syntax +`myString1 == myString2` + +[float] +=== Parameters +`myString1`: a String variable. + +`myString2`: a String variable. + + +[float] +=== Returns +`true`: if myString1 equals myString2. + +`false`: otherwise. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/concatenation.adoc b/Language/Variables/Data Types/String/Operators/concatenation.adoc index bcc3d6096..67fd53ca2 100644 --- a/Language/Variables/Data Types/String/Operators/concatenation.adoc +++ b/Language/Variables/Data Types/String/Operators/concatenation.adoc @@ -1,61 +1,61 @@ ---- -title: "+" -title_expanded: concatenation -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - - - - - -= + Concatenation - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Combines, or concatenates two Strings into one new String. The second String is appended to the first, and the result is placed in a new String. Works the same as string.concat(). - -[%hardbreaks] - - -[float] -=== Syntax -`myString3 = myString1 + myString2` - - -[float] -=== Parameters -`myString1`: a String variable. + -`myString2`: a String variable. + -`myString3`: a String variable. - - -[float] -=== Returns -New String that is the combination of the original two Strings. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "+" +title_expanded: concatenation +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + + + + + += + Concatenation + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Combines, or concatenates two Strings into one new String. The second String is appended to the first, and the result is placed in a new String. Works the same as string.concat(). + +[%hardbreaks] + + +[float] +=== Syntax +`myString3 = myString1 + myString2` + + +[float] +=== Parameters +`myString1`: a String variable. + +`myString2`: a String variable. + +`myString3`: a String variable. + + +[float] +=== Returns +New String that is the combination of the original two Strings. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/differentFrom.adoc b/Language/Variables/Data Types/String/Operators/differentFrom.adoc index b073f6b03..c26fe47d4 100644 --- a/Language/Variables/Data Types/String/Operators/differentFrom.adoc +++ b/Language/Variables/Data Types/String/Operators/differentFrom.adoc @@ -1,61 +1,61 @@ ---- -title: "!=" -title_expanded: different from -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - - - - - -= != Different From - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Compares two Strings for difference. The comparison is case-sensitive, meaning the String "hello" is not equal to the String "HELLO". Functionally the same as string.equals() - -[%hardbreaks] - - -[float] -=== Syntax -`myString1 != myString2` - - -[float] -=== Parameters -`myString1: a String variable. + -`myString2`: a String variable. - - -[float] -=== Returns -`true`: if myString1 is different from myString2. + -`false`: otherwise. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "!=" +title_expanded: different from +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + + + + + += != Different From + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Compares two Strings for difference. The comparison is case-sensitive, meaning the String "hello" is not equal to the String "HELLO". Functionally the same as string.equals() + +[%hardbreaks] + + +[float] +=== Syntax +`myString1 != myString2` + + +[float] +=== Parameters +`myString1: a String variable. + +`myString2`: a String variable. + + +[float] +=== Returns +`true`: if myString1 is different from myString2. + +`false`: otherwise. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/elementAccess.adoc b/Language/Variables/Data Types/String/Operators/elementAccess.adoc index 4ca3a7eee..bc9d73a9b 100644 --- a/Language/Variables/Data Types/String/Operators/elementAccess.adoc +++ b/Language/Variables/Data Types/String/Operators/elementAccess.adoc @@ -1,61 +1,61 @@ ---- -title: "[] " -title_expanded: element access -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - - - - - -= [] Element Access - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Allows you access to the individual characters of a String. - -[%hardbreaks] - - -[float] -=== Syntax -`char thisChar = myString1[n]` - - -[float] -=== Parameters -`thisChar`: Allowed data types: char. + -`myString1`: Allowed data types: String. + -`n`: a numeric variable. - - -[float] -=== Returns -The nth char of the String. Same as charAt(). - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "[] " +title_expanded: element access +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + + + + + += [] Element Access + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Allows you access to the individual characters of a String. + +[%hardbreaks] + + +[float] +=== Syntax +`char thisChar = myString1[n]` + + +[float] +=== Parameters +`thisChar`: Allowed data types: char. + +`myString1`: Allowed data types: String. + +`n`: a numeric variable. + + +[float] +=== Returns +The nth char of the String. Same as charAt(). + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/greaterThan.adoc b/Language/Variables/Data Types/String/Operators/greaterThan.adoc index 0c7de7f9f..26178c85c 100644 --- a/Language/Variables/Data Types/String/Operators/greaterThan.adoc +++ b/Language/Variables/Data Types/String/Operators/greaterThan.adoc @@ -1,62 +1,62 @@ ---- -title: ">" -title_expanded: greater than -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - - - - - -= > Greater Than - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Tests if the String on the left is greater than the String on the right. This operator evaluates Strings in alphabetical order, on the first character where the two differ. So, for example "b" > "a" and "2" > "1", but "999" > "1000" because 9 comes after 1. - -Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. -[%hardbreaks] - - -[float] -=== Syntax -`myString1 > myString2` - - -[float] -=== Parameters -`myString1`: a String variable. + -`myString2`: a String variable. - - -[float] -=== Returns -`true`: if myString1 is greater than myString2. + -`false`: otherwise. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: ">" +title_expanded: greater than +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + + + + + += > Greater Than + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Tests if the String on the left is greater than the String on the right. This operator evaluates Strings in alphabetical order, on the first character where the two differ. So, for example "b" > "a" and "2" > "1", but "999" > "1000" because 9 comes after 1. + +Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. +[%hardbreaks] + + +[float] +=== Syntax +`myString1 > myString2` + + +[float] +=== Parameters +`myString1`: a String variable. + +`myString2`: a String variable. + + +[float] +=== Returns +`true`: if myString1 is greater than myString2. + +`false`: otherwise. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/greaterThanOrEqualTo.adoc b/Language/Variables/Data Types/String/Operators/greaterThanOrEqualTo.adoc index da17d2671..79444aa6a 100644 --- a/Language/Variables/Data Types/String/Operators/greaterThanOrEqualTo.adoc +++ b/Language/Variables/Data Types/String/Operators/greaterThanOrEqualTo.adoc @@ -1,58 +1,58 @@ ---- -title: ">=" -title_expanded: greater than or equal to -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - -= >= Greater Than Or Equal To - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Tests if the String on the left is greater than, or equal to, the String on the right. This operator evaluate Strings in alphabetical order, on the first character where the two differ. So, for example "b" >= "a" and "2" >= "1", but "999" >= "1000" because 9 comes after 1. - -Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. - -[%hardbreaks] - - -[float] -=== Syntax -`myString1 >= myString2` - - -[float] -=== Parameters -`myString1`: variable of type String. + -`myString2: variable of type String. - - -[float] -=== Returns -`true`: if myString1 is greater than or equal to myString2. + -`false`: otherwise. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: ">=" +title_expanded: greater than or equal to +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + += >= Greater Than Or Equal To + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Tests if the String on the left is greater than, or equal to, the String on the right. This operator evaluate Strings in alphabetical order, on the first character where the two differ. So, for example "b" >= "a" and "2" >= "1", but "999" >= "1000" because 9 comes after 1. + +Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. + +[%hardbreaks] + + +[float] +=== Syntax +`myString1 >= myString2` + + +[float] +=== Parameters +`myString1`: variable of type String. + +`myString2: variable of type String. + + +[float] +=== Returns +`true`: if myString1 is greater than or equal to myString2. + +`false`: otherwise. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/lessThan.adoc b/Language/Variables/Data Types/String/Operators/lessThan.adoc index f145620cc..43dda7fa1 100644 --- a/Language/Variables/Data Types/String/Operators/lessThan.adoc +++ b/Language/Variables/Data Types/String/Operators/lessThan.adoc @@ -1,58 +1,58 @@ ---- -title: "<" -title_expanded: less thans -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - -= < Less Than - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Tests if the String on the left is less than the String on the right. This operator evaluate Strings in alphabetical order, on the first character where the two differ. So, for example "a" < "b" and "1" < "2", but "999" > "1000" because 9 comes after 1. - -Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. - -[%hardbreaks] - - -[float] -=== Syntax -`myString1 < myString2` - - -[float] -=== Parameters -`myString1`: variable of type String. + -`myString2`: variable of type String. - - -[float] -=== Returns -`true`: if myString1 is less than myString2. + -`false`: otherwise. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "<" +title_expanded: less thans +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + += < Less Than + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Tests if the String on the left is less than the String on the right. This operator evaluate Strings in alphabetical order, on the first character where the two differ. So, for example "a" < "b" and "1" < "2", but "999" > "1000" because 9 comes after 1. + +Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. + +[%hardbreaks] + + +[float] +=== Syntax +`myString1 < myString2` + + +[float] +=== Parameters +`myString1`: variable of type String. + +`myString2`: variable of type String. + + +[float] +=== Returns +`true`: if myString1 is less than myString2. + +`false`: otherwise. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/String/Operators/lessThanOrEqualTo.adoc b/Language/Variables/Data Types/String/Operators/lessThanOrEqualTo.adoc index 13c04f623..9ea998aff 100644 --- a/Language/Variables/Data Types/String/Operators/lessThanOrEqualTo.adoc +++ b/Language/Variables/Data Types/String/Operators/lessThanOrEqualTo.adoc @@ -1,63 +1,63 @@ ---- -title: "<=" -title_expanded: less than or equal -categories: [ "Data Types" ] -subCategories: [ "StringObject Operator" ] ---- - - - - - -= <= Less Than Or Equal - - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Tests if the String on the left is less than or equal to the String on the right. This operator evaluate Strings in alphabetical order, on the first character where the two differ. So, for example "a" < "b" and "1" < "2", but "999" > "1000" because 9 comes after 1. - -Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. - -[%hardbreaks] - - -[float] -=== Syntax -`myString1 <= myString2` - - -[float] -=== Parameters -`myString1`: variable of type String. + -`myString2`: variable of type String. - - -[float] -=== Returns -`true`: if myString1 is less than or equal to myString2. + -`false`: otherwise. - --- - -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION ENDS - - -// SEE ALSO SECTION -[#see_also] --- - -[float] -=== See also - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] --- -// SEE ALSO SECTION ENDS +--- +title: "<=" +title_expanded: less than or equal +categories: [ "Data Types" ] +subCategories: [ "StringObject Operator" ] +--- + + + + + += <= Less Than Or Equal + + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Tests if the String on the left is less than or equal to the String on the right. This operator evaluate Strings in alphabetical order, on the first character where the two differ. So, for example "a" < "b" and "1" < "2", but "999" > "1000" because 9 comes after 1. + +Caution: String comparison operators can be confusing when you're comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings. + +[%hardbreaks] + + +[float] +=== Syntax +`myString1 <= myString2` + + +[float] +=== Parameters +`myString1`: variable of type String. + +`myString2`: variable of type String. + + +[float] +=== Returns +`true`: if myString1 is less than or equal to myString2. + +`false`: otherwise. + +-- + +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION ENDS + + +// SEE ALSO SECTION +[#see_also] +-- + +[float] +=== See also + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] +-- +// SEE ALSO SECTION ENDS diff --git a/Language/Variables/Data Types/stringObject.adoc b/Language/Variables/Data Types/stringObject.adoc index 80e320389..396582b3d 100644 --- a/Language/Variables/Data Types/stringObject.adoc +++ b/Language/Variables/Data Types/stringObject.adoc @@ -1,155 +1,155 @@ ---- -title: "String()" -categories: [ "Variables" ] -subCategories: [ "Data Types" ] ---- - -= String() - -// OVERVIEW SECTION STARTS -[#overview] --- - -[float] -=== Description -Constructs an instance of the String class. There are multiple versions that construct Strings from different data types (i.e. format them as sequences of characters), including: - -* a constant string of characters, in double quotes (i.e. a char array) -* a single constant character, in single quotes -* another instance of the String object -* a constant integer or long integer -* a constant integer or long integer, using a specified base -* an integer or long integer variable -* an integer or long integer variable, using a specified base -* a float or double, using a specified decimal places - -Constructing a String from a number results in a string that contains the ASCII representation of that number. The default is base ten, so -[source,arduino] ----- -String thisString = String(13); ----- -gives you the String "13". You can use other bases, however. For example, - - -[source,arduino] ----- -String thisString = String(13, HEX); ----- - -gives you the String "D", which is the hexadecimal representation of the decimal value 13. Or if you prefer binary, - -[source,arduino] ----- -String thisString = String(13, BIN); ----- - -gives you the String "1101", which is the binary representation of 13. -[%hardbreaks] - - -[float] -=== Syntax -`String(val)` + -`String(val, base)` + -`String(val, decimalPlaces)` - - -[float] -=== Parameters -`val`: a variable to format as a String. Allowed data types: string, char, byte, int, long, unsigned int, unsigned long, float, double. + -`base`: (optional) the base in which to format an integral value. + -`decimalPlaces`: *only if val is float or double*. The desired decimal places. - - -[float] -=== Returns -An instance of the String class. - --- -// OVERVIEW SECTION ENDS - - - -// HOW TO USE SECTION STARTS -[#howtouse] --- - -[float] -=== Example Code -All of the following are valid declarations for Strings. -[source,arduino] ----- -String stringOne = "Hello String"; // using a constant String -String stringOne = String('a'); // converting a constant char into a String -String stringTwo = String("This is a string"); // converting a constant string into a String object -String stringOne = String(stringTwo + " with more"); // concatenating two strings -String stringOne = String(13); // using a constant integer -String stringOne = String(analogRead(0), DEC); // using an int and a base -String stringOne = String(45, HEX); // using an int and a base (hexadecimal) -String stringOne = String(255, BIN); // using an int and a base (binary) -String stringOne = String(millis(), DEC); // using a long and a base -String stringOne = String(5.698, 3); // using a float and the decimal places ----- - --- -// HOW TO USE SECTION ENDS - - -[float] -=== Functions - -[role="language"] -* #LANGUAGE# link:../string/functions/charat[charAt()] -* #LANGUAGE# link:../string/functions/compareto[compareTo()] -* #LANGUAGE# link:../string/functions/concat[concat()] -* #LANGUAGE# link:../string/functions/c_str[c_str()] -* #LANGUAGE# link:../string/functions/endswith[endsWith()] -* #LANGUAGE# link:../string/functions/equals[equals()] -* #LANGUAGE# link:../string/functions/equalsignorecase[equalsIgnoreCase()] -* #LANGUAGE# link:../string/functions/getbytes[getBytes()] -* #LANGUAGE# link:../string/functions/indexof[indexOf()] -* #LANGUAGE# link:../string/functions/lastindexof[lastIndexOf()] -* #LANGUAGE# link:../string/functions/length[length()] -* #LANGUAGE# link:../string/functions/remove[remove()] -* #LANGUAGE# link:../string/functions/replace[replace()] -* #LANGUAGE# link:../string/functions/reserve[reserve()] -* #LANGUAGE# link:../string/functions/setcharat[setCharAt()] -* #LANGUAGE# link:../string/functions/startswith[startsWith()] -* #LANGUAGE# link:../string/functions/substring[substring()] -* #LANGUAGE# link:../string/functions/tochararray[toCharArray()] -* #LANGUAGE# link:../string/functions/todouble[toDouble()] -* #LANGUAGE# link:../string/functions/toint[toInt()] -* #LANGUAGE# link:../string/functions/tofloat[toFloat()] -* #LANGUAGE# link:../string/functions/tolowercase[toLowerCase()] -* #LANGUAGE# link:../string/functions/touppercase[toUpperCase()] -* #LANGUAGE# link:../string/functions/trim[trim()] - -[float] -=== Operators - -[role="language"] -* #LANGUAGE# link:../string/operators/elementaccess[[\] (element access)] -* #LANGUAGE# link:../string/operators/concatenation[+ (concatenation)] -* #LANGUAGE# link:../string/operators/append[+= (append)] -* #LANGUAGE# link:../string/operators/comparison[== (comparison)] -* #LANGUAGE# link:../string/operators/greaterthan[> (greater than)] -* #LANGUAGE# link:../string/operators/greaterthanorequalto[>= (greater than or equal to)] -* #LANGUAGE# link:../string/operators/lessthan[< (less than)] -* #LANGUAGE# link:../string/operators/lessthanorequalto[\<= (less than or equal to)] -* #LANGUAGE# link:../string/operators/differentfrom[!= (different from)] - -[role="example"] -* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] - - -// SEE ALSO SECTION STARTS -[#see_also] --- - -[float] -=== See also - -[role="language"] - --- -// SEE ALSO SECTION ENDS +--- +title: "String()" +categories: [ "Variables" ] +subCategories: [ "Data Types" ] +--- + += String() + +// OVERVIEW SECTION STARTS +[#overview] +-- + +[float] +=== Description +Constructs an instance of the String class. There are multiple versions that construct Strings from different data types (i.e. format them as sequences of characters), including: + +* a constant string of characters, in double quotes (i.e. a char array) +* a single constant character, in single quotes +* another instance of the String object +* a constant integer or long integer +* a constant integer or long integer, using a specified base +* an integer or long integer variable +* an integer or long integer variable, using a specified base +* a float or double, using a specified decimal places + +Constructing a String from a number results in a string that contains the ASCII representation of that number. The default is base ten, so +[source,arduino] +---- +String thisString = String(13); +---- +gives you the String "13". You can use other bases, however. For example, + + +[source,arduino] +---- +String thisString = String(13, HEX); +---- + +gives you the String "D", which is the hexadecimal representation of the decimal value 13. Or if you prefer binary, + +[source,arduino] +---- +String thisString = String(13, BIN); +---- + +gives you the String "1101", which is the binary representation of 13. +[%hardbreaks] + + +[float] +=== Syntax +`String(val)` + +`String(val, base)` + +`String(val, decimalPlaces)` + + +[float] +=== Parameters +`val`: a variable to format as a String. Allowed data types: string, char, byte, int, long, unsigned int, unsigned long, float, double. + +`base`: (optional) the base in which to format an integral value. + +`decimalPlaces`: *only if val is float or double*. The desired decimal places. + + +[float] +=== Returns +An instance of the String class. + +-- +// OVERVIEW SECTION ENDS + + + +// HOW TO USE SECTION STARTS +[#howtouse] +-- + +[float] +=== Example Code +All of the following are valid declarations for Strings. +[source,arduino] +---- +String stringOne = "Hello String"; // using a constant String +String stringOne = String('a'); // converting a constant char into a String +String stringTwo = String("This is a string"); // converting a constant string into a String object +String stringOne = String(stringTwo + " with more"); // concatenating two strings +String stringOne = String(13); // using a constant integer +String stringOne = String(analogRead(0), DEC); // using an int and a base +String stringOne = String(45, HEX); // using an int and a base (hexadecimal) +String stringOne = String(255, BIN); // using an int and a base (binary) +String stringOne = String(millis(), DEC); // using a long and a base +String stringOne = String(5.698, 3); // using a float and the decimal places +---- + +-- +// HOW TO USE SECTION ENDS + + +[float] +=== Functions + +[role="language"] +* #LANGUAGE# link:../string/functions/charat[charAt()] +* #LANGUAGE# link:../string/functions/compareto[compareTo()] +* #LANGUAGE# link:../string/functions/concat[concat()] +* #LANGUAGE# link:../string/functions/c_str[c_str()] +* #LANGUAGE# link:../string/functions/endswith[endsWith()] +* #LANGUAGE# link:../string/functions/equals[equals()] +* #LANGUAGE# link:../string/functions/equalsignorecase[equalsIgnoreCase()] +* #LANGUAGE# link:../string/functions/getbytes[getBytes()] +* #LANGUAGE# link:../string/functions/indexof[indexOf()] +* #LANGUAGE# link:../string/functions/lastindexof[lastIndexOf()] +* #LANGUAGE# link:../string/functions/length[length()] +* #LANGUAGE# link:../string/functions/remove[remove()] +* #LANGUAGE# link:../string/functions/replace[replace()] +* #LANGUAGE# link:../string/functions/reserve[reserve()] +* #LANGUAGE# link:../string/functions/setcharat[setCharAt()] +* #LANGUAGE# link:../string/functions/startswith[startsWith()] +* #LANGUAGE# link:../string/functions/substring[substring()] +* #LANGUAGE# link:../string/functions/tochararray[toCharArray()] +* #LANGUAGE# link:../string/functions/todouble[toDouble()] +* #LANGUAGE# link:../string/functions/toint[toInt()] +* #LANGUAGE# link:../string/functions/tofloat[toFloat()] +* #LANGUAGE# link:../string/functions/tolowercase[toLowerCase()] +* #LANGUAGE# link:../string/functions/touppercase[toUpperCase()] +* #LANGUAGE# link:../string/functions/trim[trim()] + +[float] +=== Operators + +[role="language"] +* #LANGUAGE# link:../string/operators/elementaccess[[\] (element access)] +* #LANGUAGE# link:../string/operators/concatenation[+ (concatenation)] +* #LANGUAGE# link:../string/operators/append[+= (append)] +* #LANGUAGE# link:../string/operators/comparison[== (comparison)] +* #LANGUAGE# link:../string/operators/greaterthan[> (greater than)] +* #LANGUAGE# link:../string/operators/greaterthanorequalto[>= (greater than or equal to)] +* #LANGUAGE# link:../string/operators/lessthan[< (less than)] +* #LANGUAGE# link:../string/operators/lessthanorequalto[\<= (less than or equal to)] +* #LANGUAGE# link:../string/operators/differentfrom[!= (different from)] + +[role="example"] +* #EXAMPLE# https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings[String Tutorials^] + + +// SEE ALSO SECTION STARTS +[#see_also] +-- + +[float] +=== See also + +[role="language"] + +-- +// SEE ALSO SECTION ENDS