0% found this document useful (0 votes)
29 views4 pages

CTECH

The document discusses the Arduino programming language and platform. It covers the key components of Arduino including the circuit board, Arduino IDE software, microcontrollers, and programming structure. The main programming concepts covered are data types, variables, functions, and timing functions. Functions for digital input/output, analog input/output, and timing are described.

Uploaded by

Aekxs Haven
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

CTECH

The document discusses the Arduino programming language and platform. It covers the key components of Arduino including the circuit board, Arduino IDE software, microcontrollers, and programming structure. The main programming concepts covered are data types, variables, functions, and timing functions. Functions for digital input/output, analog input/output, and timing are described.

Uploaded by

Aekxs Haven
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CREATIVE TECHNOLOGY 10

FIRST QUARTER REVIEWER

CHAPTER 4: ARDUINO LANGUAGE


PREFERENCE

ARDUINO
• Arduino is a prototype platform (open-
source) based on an easy-to-use hardware
and software.
• It consists of a circuit board, which can be
programed (referred to as a microcontroller)
and a ready-made software called Arduino
IDE (Integrated Development Environment),
which is used to write and upload the
computer code to the physical board.
KEY FEATURES
• Able to read analog or digital input signals
from different sensors and turn it into an
output
• Can be controlled by sending a set of
instructions via Arduino IDE
• Does not need an extra piece of hardware
in order to load a new code onto the board VARIABLES
• Simplified version of C++ • Arduino data types and constants
BOARD TYPES
• Arduino boards based on ATMEGA328
microcontroller.
• Arduino boards based on ATMEGA32u4 FUNCTIONS
microcontroller.
• Arduino boards based on ATMEGA2560
microcontroller. [Digital I/O] digitalRead ()
• Arduino boards based on AT91SAM3X8E Description Reads the value from a specified digital
pin, either HIGH or LOW
microcontroller. Syntax digitalRead (pin)
ARDUINO PROGRAM STRUCTURE Parameters pin: the Arduino pin number you want to
• Arduino programs can be divided in three read
Returns HIGH or LOW
main parts: Structure, Values, and
Functions.
STRUCTURE [Digital I/O] digitalWrite ()
Description Write a HIGH or LOW value to a digital pin
• Software structure consists of two main Syntax digitalWrite (pin, value)
functions: Parameters pin: the Arduino pin number
value: HIGH or LOW
setup() function Returns Nothing
• setup() function is called when a sketch
starts.
[Digital I/O] pinMode ()
• will only run once, after each power up or Description Configures the specific pin to behave
reset of the Arduino board. either as an input or an output
loop() function Syntax pinMode (pin, mode)
Parameters pin: the Arduino pin number to set the
• the loop() function does precisely what its mode of
name suggests, and loops consecutively, mode: INPUT, OUTPUT or
INPUT_PULLUP
allowing your program to change and
Returns Nothing
respond.
FUNCTION
[Analog I/O] analogRead ()
• for controlling the Arduino board and Description Reads the value from the specified analog
performing computation pin
Syntax analogRead (pin)
Parameters pin: the name of the analog input pin to
read from
1
AMOLO 10 - EINSTEIN
CTECH 10.1 | 2023-2024

Returns The analog reading on the pin. •data type that takes up one byte of
Data type: int
memory that stores a character value
• but characters are stored as numbers
[Analog I/O] analogWrite () using ASCII Chart
Description Writes an analog value (PWM wave) to a
pin UNSIGNED CHAR
Syntax analogWrite (pin, value) • encodes number from 0 to 255
Parameters pin: the Arduino pin to write to; allowed
data types: int
BYTE
value: the duty cycle: 0 (always off) and • stores 8-bit unsigned number, 0 to 255
255 (always on);
allowed data types: int. INT
Returns Nothing • stores a 16-bit (2-byte) value
UNSIGNED INT
[Time] delay () • nstead of storing negative numbers,
Description Pauses the program for the amount of time however, they only store positive
(in milliseconds) specified as parameter.
(thousand ms = one sec) values, yielding a useful range of 0 to
Syntax delay(ms) 65,535
Parameters ms: the number of milliseconds to pause;
allowed data types: unsigned long
WORD
Returns Nothing • a word stores a 16-bit unsigned number
LONG
[Time] delayMicroseconds () • extended size variables for number
Description Pauses the program for the amount of time storage, and store 32 bits (4 bytes),
(in microseconds) specified by the
parameter. from -2,147,483,648 to 2,147,483,647.
(million us = one sec) UNSIGNED LONG
Syntax delayMircroseconds (us)
Parameters us: the number of microseconds to pause;
• unlike standard longs, unsigned longs
allowed data types: unsigned int will not store negative numbers, making
Returns Nothing their range from 0 to 4,294,967,295
SHORT
[Time] micros () • stores a 16-bit (2-byte) value. This
Description Returns the number of microseconds since yields a range of -32,768 to 32,767
the Arduino board began running the
current program. This number will overflow
FLOAT
(go back to zero), after approximately 70 •data type for floating-point number is a
minutes.
Syntax time = micros ()
number that has a decimal point
Parameters None DOUBLE
Returns Returns the number of microseconds since
the Arduino board began running the
• double implementation is exactly the
current program. Date type: unsigned same as the float, with no gain in
precision

[Time] millis () ARDUINO VARIABLES AND CONSTANTS


Description Returns the number of milliseconds
passed since the Arduino board began
VARIABLE SCOPE
running the current program. This number • Variables in C programming language,
overflows i.e. goes back to zero after
approximately 50 days. which Arduino uses, have a property called
Syntax time = micros () scope. A scope is a region of the program
Parameters None and there are three places where variables
Returns Number of milliseconds passed since the
program started. Data type: unsigned long.
can be declared.

o
Inside a function or a block, which is
ARDUINO DATA TYPES called local variables.
VOID o In the definition of function
parameters, which is called formal
• used only in function declarations;
parameters.
function is expected to return no
o Outside of all functions, which is
information to the function from which it
called global variables.
was called
LOCAL VARIABLES
BOOLEAN
• Variables that are declared inside a function
• holds one of two values, true or false or block are local variables. They can be
CHAR used only by the statements that are inside

2
AMOLO 10 - EINSTEIN
CTECH 10.1 | 2023-2024

that function or block of code. It is not COMPARISON OPERATORS


known to function outside their own. • Assume variable A holds 10 and variable B
holds 20

Operator Operator Description Example


name simple
equal to == Checks if the (A == B)
value of two is not
operands is equal true
or not, if yes then
condition
becomes true.
not equal != Checks if the (A != B)
GLOBAL VARIABLES to value of two is not
• Global variables are defined outside of all operands is equal
or not, if values
true

the functions, usually at the top of the are not equal then
program. The global variables will hold their condition
becomes true.
value throughout the lifetime of your less than < Checks if the (A < B)
program. value of left is true
operand is less
than the value of
right operand, if
yes then condition
becomes true.
greater > Checks if the (A > B)
than value of left is not
operand is true
greater than the
value of right
operand, if yes
then condition
becomes true.
less than or <= Checks if the (A <= B)
equal to value of left is true
operand is less
than or equal to
the value of right
ARDUINO OPERATORS operand, if yes
OPERATORS then condition
becomes true.
• An operator is a symbol that tells the greater >= Checks if the (A >= B)
compiler to perform specific mathematical or than or value of left is true
logical functions. equal to operand is
greater than or
equal to the value
ARITHMETIC OPERATORS of right operand, if
• Assume variable A holds 10 and variable B yes then condition
becomes true.
holds 20
Operator Operator Description Example
name simple BOOLEAN OPERATORS
assignment = Stores the value A=B • Assume variable A holds 10 and variable B
operator to the right of
the equal sign in holds 20
the variable to
the left of the Operator Operator Description Example
equal sign. name simple
addition + Adds two A+B and && Called Logical (A && B)
operands will give AND operator. If is true
30 both the
subtraction - Subtracts A – B will operands are
second operand give -10 non-zero then
from the first then condition
multiplication * Multiply both A*B will becomes true.
operands give 200 or || Called Logical (A || B) is
division / Divide B/A will OR Operator. If true
numerator by give 2 any of the two
denominator operands is non-
modulo % Modulus B%A will zero then then
Operator and give 0 condition
remainder of becomes true.
after an integer not ! Called Logical !(A &&
division NOT Operator. B) is
Use to reverses false

3
AMOLO 10 - EINSTEIN
CTECH 10.1 | 2023-2024

the logical state integer value


of its operand. If by one
a condition is compound += Add AND B += A is
true then Logical addition assignment equivalent
NOT operator operator. It to B = B+
will make false. adds right A
operand to
the left
operand and
BITWISE OPERATORS assign the
• Assume variable A holds 60 and variable B result to left
operand
holds 13 compound -= Subtract B -= A is
subtraction AND equivalent
Operator Operator Description Example assignment to B = B -
name simple operator. It A
and & Binary AND (A & B) subtracts
Operator will give right
copies a bit to 12 which operand
the result if it is 0000 from the left
exists in both 1100 operand and
operands. assign the
result to left
or | Binary OR (A | B) will
operand
Operator give 61
compound *= Multiply AND B*= A is
copies a bit if it which is
multiplication assignment equivalent
exists in either 0011 1101
operator. It to B = B* A
operand
multiplies
xor ^ Binary XOR (A ^ B) will
right
Operator give 49
operand with
copies the bit if which is
the left
it is set in one 0011 0001
operand and
operand but
assign the
not both.
result to left
not ~ Binary Ones (~A ) will
operand
Complement give -60
compound /= Divide AND B /= A is
Operator is which is
division assignment equivalent
unary and has 1100 0011
operator. It to B = B / A
the effect of
divides left
'flipping' bits.
operand with
shift left << Binary Left A << 2 will
the right
Shift Operator. give 240 operand and
The left which is assign the
operands 1111 0000 result to left
value is moved
operand
left by the
compound %= Modulus B %= A is
number of bits
modulo AND equivalent
specified by
assignment to B = B %
the right
operator. It A
operand.
takes
shift right >> Binary Right A >> 2 will
modulus
Shift Operator. give 15 using two
The left which is operands
operands 0000 1111 and assign
value is moved the result to
right by the left operand
number of bits
compound |= bitwise A |= 2 is
specified by
bitwise or inclusive OR same as A
the right
and =A|2
operand.
assignment
operator
compound &= Bitwise AND A &= 2 is
COMPOUND OPERATORS bitwise and assignment same as A
operator =A&2
• Assume variable A holds 10 and variable B
holds 20

Operator Operator Description Example


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

4
AMOLO 10 - EINSTEIN

You might also like