Skip to content

Language content #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Language/Functions/Communication/serial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ The *Arduino Leonardo* board uses `Serial1` to communicate via TTL (5V) serial o

[float]
=== Functions
http://arduino.cc[if] (Serial) +
http://arduino.cc[available()] +
http://arduino.cc[begin()] +
http://arduino.cc[end()] +
http://arduino.cc[find()] +
http://arduino.cc[findUntil()] +
http://arduino.cc[flush()] +
http://arduino.cc[parseFloat()] +
http://arduino.cc[parseInt()] +
http://arduino.cc[peek()] +
http://arduino.cc[print()] +
http://arduino.cc[println()] +
http://arduino.cc[read()] +
http://arduino.cc[readBytes()] +
http://arduino.cc[readBytesUntil()] +
http://arduino.cc[setTimeout()] +
http://arduino.cc[write()] +
http://arduino.cc[serialEvent()]
link:IfSerial{ext-relative}[If] (Serial) +
link:Available{ext-relative}[available()] +
link:Begin{ext-relative}[begin()] +
link:End{ext-relative}[end()] +
link:Find{ext-relative}[find()] +
link:FindUntil{ext-relative}[findUntil()] +
link:Flush{ext-relative}[flush()] +
link:ParseFloat{ext-relative}[parseFloat()] +
link:ParseInt{ext-relative}[parseInt()] +
link:Peek{ext-relative}[peek()] +
link:Print{ext-relative}[print()] +
link:PrintLn{ext-relative}[println()] +
link:Read{ext-relative}[read()] +
link:ReadBytes{ext-relative}[readBytes()] +
link:ReadBytesUntil{ext-relative}[readBytesUntil()] +
link:SetTimeout{ext-relative}[setTimeout()] +
link:Write{ext-relative}[write()] +
link:SerialEvent{ext-relative}[serialEvent()]

'''

Expand All @@ -75,4 +75,4 @@ http://arduino.cc[serialEvent()]


--
// SEEALSO SECTION ENDS
// SEEALSO SECTION ENDS
76 changes: 76 additions & 0 deletions Language/Structure/Arithmetic Operators/addition.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
:source-highlighter: pygments
:pygments-style: arduino
:ext-relative: adoc


= + 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
[source,arduino]
----
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
[%hardbreaks]
--
// OVERVIEW SECTION ENDS




// HOW TO USE SECTION STARTS
[#howtouse]
--

[float]
=== Example Code

[source,arduino]
----
int a = 5, b = 10, 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, 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]

[float]
=== See also

[role="language"]
* #LANGUAGE# link:subtraction{ext-relative}[Subtraction]
* #LANGUAGE# link:multiplication{ext-relative}[Multiplication]
* #LANGUAGE# link:division{ext-relative}[Division]
--
// HOW TO USE SECTION ENDS
57 changes: 57 additions & 0 deletions Language/Structure/Arithmetic Operators/assignment.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
:source-highlighter: pygments
:pygments-style: arduino
:ext-relative: adoc


= = 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]

[float]
=== See also

[role="language"]
* #LANGUAGE# link:../Control%20Structures/if{ext-relative}[if (conditional operators)]
* #LANGUAGE# link:../../Variables/Data%20Types/char[char]
* #LANGUAGE# link:../../Variables/Data%20Types/int[int]
* #LANGUAGE# link:../../Variables/Data%20Types/long[long]

--
// HOW TO USE SECTION ENDS
76 changes: 76 additions & 0 deletions Language/Structure/Arithmetic Operators/division.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
:source-highlighter: pygments
:pygments-style: arduino
:ext-relative: adoc


= / 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
[source,arduino]
----
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
[%hardbreaks]

--
// OVERVIEW SECTION ENDS




// HOW TO USE SECTION STARTS
[#howtouse]
--

[float]
=== Example Code

[source,arduino]
----
int a = 50, b = 10, 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, 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]

[float]
=== See also

[role="language"]
* #LANGUAGE# link:addition{ext-relative}[addition]
* #LANGUAGE# link:subtraction{ext-relative}[subtraction]
* #LANGUAGE# link:multiplication{ext-relative}[multiplication]

--
// HOW TO USE SECTION ENDS
82 changes: 82 additions & 0 deletions Language/Structure/Arithmetic Operators/modulo.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
:source-highlighter: pygments
:pygments-style: arduino
:ext-relative: adoc


= % Modulo


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
*Modulo* operation calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array). The `%` (percent) symbol is used to carry out modulo operation.
[%hardbreaks]


[float]
=== Syntax
[source,arduino]
----
remainder = dividend % divisor;
----

[float]
=== Parameters
`remainder` : variable. *Allowed data types:* int, float, double +
`dividend` : variable or constant. *Allowed data types:* int +
`divisor` : *non zero* variable or constant. *Allowed data types:* int
[%hardbreaks]

--
// OVERVIEW SECTION ENDS



// HOW TO USE SECTION STARTS
[#howtouse]
--

[float]
=== Example Code

[source,arduino]
----
int x = 0;
x = 7 % 5; // x now contains 2
x = 9 % 5; // x now contains 4
x = 5 % 5; // x now contains 0
x = 4 % 5; // x now contains 4
----

[source,arduino]
----
/* update one value in an array each time through a loop */

int values[10];
int i = 0;

void setup() {}

void loop()
{
values[i] = analogRead(0);
i = (i + 1) % 10; // modulo operator rolls over variable
}
----
[%hardbreaks]

[float]
=== Notes and Warnings
The modulo operator does not work on floats.
[%hardbreaks]

[float]
=== See also

[role="language"]
* #LANGUAGE# link:division{ext-relative}[Division]
--
// HOW TO USE SECTION ENDS
Loading