Intro To Microprocessor and Microcontroller Lecture 2
Intro To Microprocessor and Microcontroller Lecture 2
Intro To Microprocessor and Microcontroller Lecture 2
MICROCONTROLLER
IKSAN BUKHORI, M.PHIL.
ARDUINO BOARD
MEET THE FAMILY
ARDUINO UNO BOARD
ATMEGA 328P ARCHITECTURE
AVR CPU ARCHITECTURE
ARDUINO PROGRAMMING
ARDUINO IDE
See:
http://arduino.cc/en/Guide/Environment
for more information
ARDUINO PROGRAMMING: BASICS
Brackets
There are two types of brackets used in the Arduino coding, which are listed below:
o Parentheses ( )
The parentheses brackets are the group of the arguments, such as method, function, or a code statement. These
are also used to group the math equations.
o Curly Brackets { }
The statements in the code are enclosed in the curly brackets. We always require closed curly brackets to
match the open curly bracket in the code or sketch.
ARDUINO PROGRAMMING: BASICS
Line Comment
There are two types of line comments, which are listed below:
o // Single line comment
The text that is written after the two forward slashes are considered as a single line comment. The compiler
ignores the code written after the two forward slashes. The comment will not be displayed in the output. Such
text is specified for a better understanding of the code or for the explanation of any code statement.
The // (two forward slashes) are also used to ignore some extra lines of code without deleting it.
o / * Multi - line comment */
The Multi-line comment is written to group the information for clear understanding. It starts with the single
forward slash and an asterisk symbol (/ *). It also ends with the / *. It is commonly used to write the larger
text. It is a comment, which is also ignored by the compiler.
ARDUINO PROGRAMMING: BASICS
Setup Vs Loop
o Setup
It contains an initial part of the code to be executed. The pin modes, libraries, variables, etc., are initialized in
the setup section. It is executed only once during the uploading of the program and after reset or power up of
the Arduino board.
Zero setup () resides at the top of each sketch. As soon as the program starts running, the code inside the curly
bracket is executed in the setup and it executes only once.
o Loop
The loop contains statements that are executed repeatedly. The section of code inside the curly brackets is
repeated depending on the value of variables.
ARDUINO PROGRAMMING: BASICS
Timing
The time in Arduino programming is measured in a millisecond.
Where, 1 sec = 1000 milliseconds
We can adjust the timing according to the milliseconds.
For example, for a 5-second delay, the time displayed will be 5000 milliseconds.
ARDUINO PROGRAMMING: BASICS
pinMode
The specific pin number is set as the INPUT or OUTPUT in the pinMode () function.
The Syntax is: pinMode (pin, mode)
Where,
pin: It is the pin number. We can select the pin number according to the requirements.
Mode: We can set the mode as INPUT or OUTPUT according to the corresponding pin number.
ARDUINO PROGRAMMING: BASICS
digitalWrite() vs DigitalRead()
The digitalRead () function will read the HIGH/LOW value from the digital pin, and the digitalWrite ()
function is used to set the HIGH/LOW value of the digital pin.
delay()
The delay () function is a blocking function to pause a program from doing a task during the specified
duration in milliseconds.
THANK YOU