You are on page 1of 18

Arduino Cheat Sheet

Struktur
Tipe Data
Variable
• Global Variable
• Local Variable
Operator
Operator name Operator simple Description Example

Aritmatika assignment operator =


Stores the value to the right of the
equal sign in the variable to the left A = B
of the equal sign.

A + B will give
addition + Adds two operands
30

Subtracts second operand from the A - B will give -


subtraction - first 10

A * B will give
multiplication * Multiply both operands
200

division / Divide numerator by denominator B / A will give 2

modulo % Modulus Operator and remainder B % A will give


of after an integer division 0
Operator name Operator simple Description Example

Operator equal to ==
Checks if the value of two
operands is equal or not, if yes
then condition becomes true.
(A == B) is not true

Perbandingan not equal to !=


Checks if the value of two
operands is equal or not, if (A != B) is true
values are not equal then
condition becomes true.
Checks if the value of left
less than < operand is less than the value of (A < B) is true
right operand, if yes then
condition becomes true.

Checks if the value of left


greater than > operand is greater than the value (A > B) is not true
of right operand, if yes then
condition becomes true.
Checks if the value of left
less than or equal operand is less than or equal to
to <= the value of right operand, if yes (A <= B) is true
then condition becomes true.

Checks if the value of left


greater than or operand is greater than or equal
>= to the value of right operand, if (A >= B) is not true
equal to yes then condition becomes
true.
Contoh Kasus Perbandingan
A Perbandingan B Result

9 = 9 TRUE

10 != 9 TRUE

9 < 8 FALSE

10 > 2 TRUE

3 <= 7 TRUE

4 >= 8 FALSE
Operator
Operator name Operator simple Description Example

Booelan and &&


Called Logical AND operator. If
both the operands are non-zero
(A && B) is true
then then condition becomes
true.

Called Logical OR Operator. If any


or || of the two operands is non-zero (A || B) is true
then then condition becomes
true.

Called Logical NOT Operator. Use


to reverses the logical state of its
not ! operand. If a condition is true !(A && B) is false
then Logical NOT operator will
make false.
Contoh Kasus 1 Boolean
A Perbandingan B Result

TRUE && TRUE TRUE

TRUE && FALSE FALSE

TRUE || FALSE TRUE

TRUE || TRUE TRUE

FALSE || FALSE FALSE

!(FALSE) && !(TRUE) FALSE


Contoh Kasus 2 Boolean
A Perbandingan B Result

(9 > 10) && TRUE FALSE

(5 != 4) && (1 > 2) FALSE

(9 > 10) || FALSE FALSE

(1 > 2) || (2 >= 2) TRUE

!(TRUE) || !(TRUE) FALSE

(9 > 10) && (1 > 2) && !(FALSE) && !(FALSE) FALSE


Operator Operator name
increment
Operator simple
++
Description
Increment operator, increases integer
Example
A++ will give 11
value by one
Senyawa decrement --
Decrement operator, decreases integer
value by one
A-- will give 9

(Compound) compound addition +=


Add AND assignment operator. It adds
right operand to the left operand and B += A is equivalent to B = B+ A
assign the result to left operand
Jika Subtract AND assignment operator. It
compound subtraction -= subtracts right operand from the left B -= A is equivalent to B = B - A
A=10 operand and assign the result to left
operand
B=1 Multiply AND assignment operator. It
multiplies right operand with the left
compound multiplication *= B*= A is equivalent to B = B* A
operand and assign the result to left
operand
Divide AND assignment operator. It
divides left operand with the right
compound division /= B /= A is equivalent to B = B / A
operand and assign the result to left
operand
Modulus AND assignment operator. It
compound modulo %= takes modulus using two operands and B %= A is equivalent to B = B %
A
assign the result to left operand
bitwise inclusive OR and assignment
compound bitwise or |= operator A |= 2 is same as A = A | 2
compound bitwise and &= Bitwise AND assignment operator A &= 2 is same as A = A & 2
IF
• Berapa nilai A pada
setelah baris ke 10 ?
• Berapa nilai A
setelah baris ke 13?
• Berapa nilai B
setelah baris ke 14?
IF-ELSE
• Berapa nilai A
setelah baris akhir
program ?
• Berapa nilai B
setelah akhir
Program?
Switch-Case
• Jika phase bernilai 0 fungsi apakah yang
akan dijalankan?
• Jika phase bernilai 3 fungsi apakah yang
akan dijalankan?
? : conditional operator Syntax
• expression1 ? expression2 : expression3

• Berapakah nilai x ?
While Loop
• Berapa nilai a yang akan tampil pada
baris ke-8 ?
do-while
• Berapa nilai a yang akan tampil
pada baris ke-7?
for
• Berapa nilai total pada baris ke 7 pada
gambar dibawah ?

You might also like