Skip to content

Commit 6b22708

Browse files
committed
Merge pull request #4 from arduino/Structure
Add Contents for Structure. Checked the texts. They are ok
2 parents bc6ede7 + 1a4095a commit 6b22708

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3011
-61
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= + Addition
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
*Addition* is one of the four primary arithmetic operations. The operator `+` (plus) operates on two operands to produce the sum.
16+
[%hardbreaks]
17+
18+
19+
[float]
20+
=== Syntax
21+
[source,arduino]
22+
----
23+
sum = operand1 + operand2;
24+
----
25+
26+
[float]
27+
=== Parameters
28+
`sum` : variable. *Allowed data types:* int, float, double, byte, short, long +
29+
`operand1` : variable or constant. *Allowed data types:* int, float, double, byte, short, long +
30+
`operand2` : variable or constant. *Allowed data types:* int, float, double, byte, short, long
31+
[%hardbreaks]
32+
--
33+
// OVERVIEW SECTION ENDS
34+
35+
36+
37+
38+
// HOW TO USE SECTION STARTS
39+
[#howtouse]
40+
--
41+
42+
[float]
43+
=== Example Code
44+
45+
[source,arduino]
46+
----
47+
int a = 5, b = 10, c = 0;
48+
c = a + b; // the variable 'c' gets a value of 15 after this statement is executed
49+
----
50+
[%hardbreaks]
51+
52+
[float]
53+
=== Notes and Warnings
54+
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).
55+
56+
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.
57+
58+
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.
59+
60+
[source,arduino]
61+
----
62+
float a = 5.5, b = 6.6;
63+
int c = 0;
64+
c = a + b; // the variable 'c' stores a value of 12 only as opposed to the expected sum of 12.1
65+
----
66+
[%hardbreaks]
67+
68+
[float]
69+
=== See also
70+
71+
[role="language"]
72+
* #LANGUAGE# link:subtraction{ext-relative}[Subtraction]
73+
* #LANGUAGE# link:multiplication{ext-relative}[Multiplication]
74+
* #LANGUAGE# link:division{ext-relative}[Division]
75+
--
76+
// HOW TO USE SECTION ENDS
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= = Assignment (single equal sign)
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
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.
16+
[%hardbreaks]
17+
18+
--
19+
// OVERVIEW SECTION ENDS
20+
21+
22+
23+
24+
// HOW TO USE SECTION STARTS
25+
[#howtouse]
26+
--
27+
28+
[float]
29+
=== Example Code
30+
31+
32+
33+
[source,arduino]
34+
----
35+
int sensVal; // declare an integer variable named sensVal
36+
sensVal = analogRead(0); // store the (digitized) input voltage at analog pin 0 in SensVal
37+
----
38+
[%hardbreaks]
39+
40+
[float]
41+
=== Notes and Warnings
42+
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.
43+
44+
2. Don't confuse the assignment operator [ = ] (single equal sign) with the comparison operator [ == ] (double equal signs), which evaluates whether two expressions are equal.
45+
[%hardbreaks]
46+
47+
[float]
48+
=== See also
49+
50+
[role="language"]
51+
* #LANGUAGE# link:../Control%20Structures/if{ext-relative}[if (conditional operators)]
52+
* #LANGUAGE# link:../../Variables/Data%20Types/char[char]
53+
* #LANGUAGE# link:../../Variables/Data%20Types/int[int]
54+
* #LANGUAGE# link:../../Variables/Data%20Types/long[long]
55+
56+
--
57+
// HOW TO USE SECTION ENDS
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= / Division
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
*Division* is one of the four primary arithmetic operations. The operator `/` (slash) operates on two operands to produce the result.
16+
[%hardbreaks]
17+
18+
19+
[float]
20+
=== Syntax
21+
[source,arduino]
22+
----
23+
result = numerator / denominator;
24+
----
25+
26+
[float]
27+
=== Parameters
28+
`result` : variable. *Allowed data types:* int, float, double, byte, short, long +
29+
`numerator` : variable or constant. *Allowed data types:* int, float, double, byte, short, long +
30+
`denominator` : *non zero* variable or constant. *Allowed data types:* int, float, double, byte, short, long
31+
[%hardbreaks]
32+
33+
--
34+
// OVERVIEW SECTION ENDS
35+
36+
37+
38+
39+
// HOW TO USE SECTION STARTS
40+
[#howtouse]
41+
--
42+
43+
[float]
44+
=== Example Code
45+
46+
[source,arduino]
47+
----
48+
int a = 50, b = 10, c = 0;
49+
c = a / b; // the variable 'c' gets a value of 5 after this statement is executed
50+
----
51+
[%hardbreaks]
52+
53+
[float]
54+
=== Notes and Warnings
55+
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.
56+
57+
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.
58+
59+
[source,arduino]
60+
----
61+
float a = 55.5, b = 6.6;
62+
int c = 0;
63+
c = a / b; // the variable 'c' stores a value of 8 only as opposed to the expected result of 8.409
64+
----
65+
[%hardbreaks]
66+
67+
[float]
68+
=== See also
69+
70+
[role="language"]
71+
* #LANGUAGE# link:addition{ext-relative}[addition]
72+
* #LANGUAGE# link:subtraction{ext-relative}[subtraction]
73+
* #LANGUAGE# link:multiplication{ext-relative}[multiplication]
74+
75+
--
76+
// HOW TO USE SECTION ENDS
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= % Modulo
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
*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.
16+
[%hardbreaks]
17+
18+
19+
[float]
20+
=== Syntax
21+
[source,arduino]
22+
----
23+
remainder = dividend % divisor;
24+
----
25+
26+
[float]
27+
=== Parameters
28+
`remainder` : variable. *Allowed data types:* int, float, double +
29+
`dividend` : variable or constant. *Allowed data types:* int +
30+
`divisor` : *non zero* variable or constant. *Allowed data types:* int
31+
[%hardbreaks]
32+
33+
--
34+
// OVERVIEW SECTION ENDS
35+
36+
37+
38+
// HOW TO USE SECTION STARTS
39+
[#howtouse]
40+
--
41+
42+
[float]
43+
=== Example Code
44+
45+
[source,arduino]
46+
----
47+
int x = 0;
48+
x = 7 % 5; // x now contains 2
49+
x = 9 % 5; // x now contains 4
50+
x = 5 % 5; // x now contains 0
51+
x = 4 % 5; // x now contains 4
52+
----
53+
54+
[source,arduino]
55+
----
56+
/* update one value in an array each time through a loop */
57+
58+
int values[10];
59+
int i = 0;
60+
61+
void setup() {}
62+
63+
void loop()
64+
{
65+
values[i] = analogRead(0);
66+
i = (i + 1) % 10; // modulo operator rolls over variable
67+
}
68+
----
69+
[%hardbreaks]
70+
71+
[float]
72+
=== Notes and Warnings
73+
The modulo operator does not work on floats.
74+
[%hardbreaks]
75+
76+
[float]
77+
=== See also
78+
79+
[role="language"]
80+
* #LANGUAGE# link:division{ext-relative}[Division]
81+
--
82+
// HOW TO USE SECTION ENDS
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
:source-highlighter: pygments
2+
:pygments-style: arduino
3+
:ext-relative: adoc
4+
5+
6+
= * Multiplication
7+
8+
9+
// OVERVIEW SECTION STARTS
10+
[#overview]
11+
--
12+
13+
[float]
14+
=== Description
15+
*Multiplication* is one of the four primary arithmetic operations. The operator `*` (asterisk) operates on two operands to produce the product.
16+
[%hardbreaks]
17+
18+
19+
[float]
20+
=== Syntax
21+
[source,arduino]
22+
----
23+
product = operand1 * operand2;
24+
----
25+
26+
[float]
27+
=== Parameters
28+
`product` : variable. *Allowed data types:* int, float, double, byte, short, long +
29+
`operand1` : variable or constant. *Allowed data types:* int, float, double, byte, short, long +
30+
`operand2` : variable or constant. *Allowed data types:* int, float, double, byte, short, long
31+
[%hardbreaks]
32+
33+
--
34+
// OVERVIEW SECTION ENDS
35+
36+
37+
38+
39+
// HOW TO USE SECTION STARTS
40+
[#howtouse]
41+
--
42+
43+
[float]
44+
=== Example Code
45+
46+
[source,arduino]
47+
----
48+
int a = 5, b = 10, c = 0;
49+
c = a * b; // the variable 'c' gets a value of 50 after this statement is executed
50+
----
51+
[%hardbreaks]
52+
53+
[float]
54+
=== Notes and Warnings
55+
1. The multiplication operation can overflow if the result is bigger than that which can be stored in the data type.
56+
57+
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.
58+
59+
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.
60+
61+
[source,arduino]
62+
----
63+
float a = 5.5, b = 6.6;
64+
int c = 0;
65+
c = a * b; // the variable 'c' stores a value of 36 only as opposed to the expected product of 36.3
66+
----
67+
[%hardbreaks]
68+
69+
[float]
70+
=== See also
71+
72+
[role="language"]
73+
* #LANGUAGE# link:addition{ext-relative}[Addition]
74+
* #LANGUAGE# link:subtraction{ext-relative}[subtraction]
75+
* #LANGUAGE# link:division{ext-relative}[Division]
76+
77+
--
78+
// HOW TO USE SECTION ENDS

0 commit comments

Comments
 (0)