SlideShare uma empresa Scribd logo
1 de 51
Programming
By: Froilan G. Cantillo
1
Computer Engineering Department
President Ramon Magsaysay State University
Logic
Design
and
By: Froilan G. Cantillo
Programming Logic and Design
INTRODUCTION OF COMPUTER PROGRAMMING
2
Computer Program – Is a list of instructions that the computer machine
follows to properly accept input, correctly process them and present the
results in the most understandable way.
Computer Programming – is considered to be an art and at the same
time a science. It is an art because there is no standard way to interpret a
problem and solve it using a standard form of programming procedures
and styles. It is fast becoming a science because standard programming
practice is starting to be adopted.
Programs fall into two major classes:
• Application Programs – application program is one that carries out
some function directly for a user, such as word processing or game-
playing.
• Operating Systems – operating system is a program that manages the
computer and the various resources and devices connected to it, such
as RAM (random access memory), hard drives, monitors, keyboards,
printers, and modems, so that they may be used by other programs.
A programmer uses another type of program called a text editor to write
the new program in a special notation called a programming language.
With the text editor, the programmer creates a text file, which is an ordered
list of instructions, also called the program source file. The individual
instructions that make up the program source file are called source code.
At this point, a special applications program translates the source code
into machine language, or object code — a format that the operating
system will recognize as a proper program and be able to execute.
Three types of applications programs translate from source code to object
code:
• Compilers – Computer software that translates (compiles) source code
written in a high-level language (e.g., C++) into a set of machine-
language instructions that can be understood by a digital computer's
CPU. Compilers are very large programs, with error-checking and other
abilities
• Interpreters – Is a computer program that directly executes instructions
written in a programming or scripting language, without requiring them
previously to have been compiled into a machine language program. An
interpreter generally uses one of the following strategies for program
execution:
o Parse the source code and perform its behavior directly;
o Translate source code into some efficient intermediate
representation and immediately execute this;
o Explicitly execute stored precompiled code made by a compiler
which is part of the interpreter system
• Assemblers – Is a program that converts assembly language into
machine code. It takes the basic commands and operations from
assembly code and converts them into binary code that can be
recognized by a specific type of processor. Assemblers are similar to
compilers in that they produce executable code
By: Froilan G. Cantillo
Programming Logic and Design
INTRODUCTION OF COMPUTER PROGRAMMING
3
Computer is composed of:
1. CPU (Central Processing Unit) – this is where all mathematical and
logical forms of processing are done on data.
2. Memory – before a computer can do any productive work such as
programming, it has to remember things such as data it needs to
produce information.
3. Input and Output Device – data have to come into the computer by
first entering them through input devices. Ex. Keyboard. After the
computer executes a program to process data and produce
information, this information remains in the memory. Part of the
program has to show these results to the outside world. Output devices
such as monitor screen and printers are used to display the results to
the user.
4. Software – computers today come bundled with some software
already installed in them. Operating System – performs for the
programmer many tasks that used to be very difficult to program
Two forms of Memory
• Internal Memory (RAM-Random Access Memory) – stores programs
and data that are executed and processed by the computer.
• Secondary Memory – supplements RAM so those computers are able
to permanently save programs and data that are not yet needed for
execution and processing. Ex. Floppy disk, hard disk & etc.
The following are standard Operating System functions.
• Validating user identification every time the user uses the computer
• Provides standard functions like editor, compilers and linkers
• Manages files of the user by providing functions like Copy, Delete,
Append
• Retrieves data out of data files
• Manages memory for the user by determining where in the memory a
program is to be loaded every time it is called to run
• Makes communication between the CPU, Memory and input/output
devices transparent to the user or the user are unaware of these things
while they are at work.
By: Froilan G. Cantillo
Programming Logic and Design
INTRODUCTION OF COMPUTER PROGRAMMING
4
High level languages
• Programming languages that are closer to human language than to
machine language. They are characterized to use common English
words as their instructions. Aside from that, high level languages have
the following characteristics:
• Requires additional step of compilation or translation so that from high-
level, another program that has exactly the same meaning and intended
results in low-level or machine language can be generated and loaded
into the computer and executed.
• A compiled program is usually not as efficient as when the program was
originally written in machine language or assembly. This is due to the
fact that compilers add a lot of extra overheads in terms of memory and
non-optimized logical translations.
Each of these programming languages was designed to solve particular
kinds of problems.
• COBOL – Common Business Oriented Language was designed to
solve business problems like accounting.
• FORTRAN – Formula Translation is a high level language used for
scientific and engineering applications.
• Pascal and C – are general-purpose language. They are high-level
language but they can be embedded with assembly language code
effectively making these languages middle-level languages. C language
is responsible in the implementation of major software including
operating systems, compilers and software development tools
The Simplest computer programs perform three basic operations:
• Get the input from the keyboard.
• Process the input data.
• Display the results on the screen.
INPUT DATA PROCESS DATA
DISPLAY ALL
RESULT
By: Froilan G. Cantillo
Programming Logic and Design
COMPUTER LANGUAGE
5
Programming Language
• A programming language is a set of rules that provides a way of telling a
computer what operations to perform.
• A programming language is a set of rules for communicating an
algorithm
• It provides a linguistic framework for describing computations
• The grammatical rules are called syntax.
• Each programming language has a different set of syntax rules.
Why are there so many programming languages?
• Programming languages have evolved over time as better ways have
been developed to design them.
o First programming languages were developed in the 1950s.
o Since then thousands of languages have been developed.
• Different programming languages are designed for different types of
programs.
Classification of Programming Language
Programming Languages - Generations
• High level languages
o 4th Generation Data query, analysis and reporting
o 3rd Generation Imperative
• Low level languages
o 2nd Generation Assembly
o 1st Generation Machine code
By: Froilan G. Cantillo
Programming Logic and Design
COMPUTER LANGUAGE
6
Low-Level Language:
• Machine code and Assembly code
High-Level Language:
• A programming language that allows programs to be written using
English keywords and is platform independent
Low-Level Language:
• Advantages
o Achieves a smaller memory footprint (compact).
o Achieves better code optimization and therefore code will run
faster and more efficiently.
o Allows direct manipulation if the registers on the processors,
giving high levels of control.
o Processors in these systems may be slow and have limited
memory so the efficiency of assembly language or machine code
is needed. Also useful real time control systems where speed is
very important.
o Since you are writing at machine level you control the level of the
code created.
o Can be easily modified.
• Disadvantages
o More difficult to understand, maintain and debug than high level
languages.
o More difficult to write without making errors.
o Machine dependent making it difficult to port to a different
instruction set processor Memory addresses and operations
have to be remembered Low Level Languages.
By: Froilan G. Cantillo
Programming Logic and Design
COMPUTER LANGUAGE
7
What are the types of programming languages?
• First Generation Languages
• Second Generation Languages
• Third Generation Languages
• Fourth Generation Languages
• Fifth Generation Languages
First Generation Language
• Machine language
o Operation code – such as addition or subtraction.
o Operands – that identify the data to be processed.
o Machine language is machine dependent as it is the only language the
computer can understand.
o Very efficient code but very difficult to write.
Second Generation Languages
• Assembly languages
o Symbolic operation codes replaced binary operation codes.
o Assembly language programs needed to be “assembled” for execution
by the computer. Each assembly language instruction is translated into
one machine language instruction.
o Very efficient code and easier to write.
o Does the world need new languages?
Third Generation Languages
• Closer to English but included simple mathematical notation.
o Programs written in source code which must be translated into
machine language programs called object code.
o The translation of source code to object code is accomplished by
a machine language system program called a compiler.
• Alternative to compilation is interpretation which is accomplished by a
system program called an interpreter.
• Common third generation languages
o FORTRAN
o COBOL
o C and C++
o Visual Basic
Fourth Generation Languages
• A high level language (4GL) that requires fewer instructions to
accomplish a task than a third generation language.
• Used with databases
o Query languages
o Report generators
o Forms designers
o Application generators
By: Froilan G. Cantillo
Programming Logic and Design
COMPUTER LANGUAGE
8
Fifth Generation Languages
• Declarative languages
• Functional(?): Lisp, Scheme, SML
o Also called applicative
o Everything is a function
• Logic: Prolog
o Based on mathematical logic
o Rule- or Constraint-based
Beyond Fifth Generation Language
• Though no clear definition at present, natural language programs
generally can be interpreted and executed by the computer with no
other action by the user than stating their question.
• Limited capabilities at present.
The principal paradigm
• Imperative Programming (C)
• Object-Oriented Programming (C++)
• Logic/Declarative Programming (Prolog)
• Functional/Applicative Programming (Lisp)
Traditional Programming Language
• FORTRAN
o FORmula TRANslation.
o Developed at IBM in the mid-1950s.
o Designed for scientific and mathematical applications by
scientists and engineers.
• COBOL
o COmmon Business Oriented Language.
o Developed in 1959. ◦ Designed to be common to many different
computers.
o Typically used for business applications.
• BASIC
o Beginner’s All-purpose Symbolic Instruction Code.
o Developed at Dartmouth College in mid 1960s.
o Developed as a simple language for students to write programs
with which they could interact through terminals.
• C
o Developed by Bell Laboratories in the early 1970s.
o Provides control and efficiency of assembly language while
having third generation language features.
o Often used for system programs. ◦ UNIX is written in C.
By: Froilan G. Cantillo
Programming Logic and Design
COMPUTER LANGUAGE
9
Object-Oriented Programming Language
• Simula
o First object-oriented language
o Developed by Ole Johan Dahl in the 1960s.
• Smalltalk
o First purely object-oriented language.
o Developed by Xerox in mid-1970s.
o Still in use on some computers.
• C++
o It is C language with additional features.
o Widely used for developing system and application software.
o Graphical user interfaces can be developed easily with visual
programming tools.
• JAVA
o An object-oriented language similar to C++ that eliminates lots of
C++’s problematic features.
o Allows a web page developer to create programs for applications,
called applets that can be used through a browser.
o Objective of JAVA developers is that it be machine, platform and
operating system independent.
Special Programming Language
• Scripting Languages
o JavaScript and VBScript
o Php and ASP
o Perl and Python
• Command Languages
o sh, csh, bash
• Text processing Languages
o LaTex, PostScript
• HTML
o HyperText Markup Language.
o Used on the Internet and the World Wide Web (WWW).
o Web page developer puts brief codes called tags in the page to
indicate how the page should be formatted.
• XML
o Extensible Markup Language.
o A language for defining other languages.
By: Froilan G. Cantillo
Programming Logic and Design
BRIEF HISTORY OF PROGRAMMING LANGUAGE
10
• 1842- 1843 (First Computer Program created by Ada Lovelace
o Work on the Charles Babbage’s analytical engine. A complete
detail a method for calculating Bernoulli numbers with the engine
• 1890 Census data on punch cards encoded by Herman Hollerith
• 1943-1945 (PLANKALKÜL DEVELOPED FOR THE GERMAN Z3 BY
KONRAD ZUSE)
o An early high-level programming language to be designed for a
computer but was not implemented.
• 1949 (SHORT CODE DEVELOP BY JOHN MAUCHLY)
o One of the first high-level languages ever developed for an
electronic computer. Short code statements are represented by
mathematical expressions.
• 1952 (MANCHESTER MARK 1 DEVELOPED BY ALICK GLENNIE)
o Considered as first compiled high – level programming language.
o Automatically convert language into a machine code.
• 1957 (FORTRAN CREATED BY JOHN BACKUS)
o For numeric and scientific computing (as an alternative to
assembly language).
o Oldest programming language used today.
• 1959 COBOL (COMMON BUSINESS- ORIENTED LANGUAGE)
CREATED BY SHORT RANGE COMMITTEE)
o High-level. Primarily for business computing. First programming
language to be mandated by the US Department of Defense.
Primary Uses: Business software (esp. finance and
administration systems, but also banks, insurance agencies,
governments, military agencies) Used By: Credit cards, ATMs
*Fun Fact Action movie The Terminator used samples of Cobol
source code for the text shown in the Terminator’s vision display.
• 1964 BASIC (BEGINNER’S ALL-PURPOSE SYMBOLIC
INSTRUCTION CODE) CREATED BY JOHN GEORGE KENNY AND
THOMAS EUGENE KURTZ (SRC)
o Designed for simplicity.
o Computer games were often written in Basic. (Microsoft’s Altair,
Apple II)
• 1970 (PASCAL (BLAISE PASCAL) CREATED BY NIKLAUS WIRTH)
o For teaching structured programming and data structuring.
Commonly used for Windows Application development.
• 1972 (C CREATED BY DENNIS RITCHIE OF BELL LABS)
o o Currently the world’s most popular programming language.2
Many leading languages are derivatives, including C#, Java,
JavaScript, Perl, PHP, and Python. System programming,
computer game development.
By: Froilan G. Cantillo
Programming Logic and Design
BRIEF HISTORY OF PROGRAMMING LANGUAGE
11
• 1980 (ADA (AFTER ADA LOVELACE, CREATED BY JEAN ICHBIAH)
o Derived from Pascal.
o For developing large software systems.
o Primary Uses: Dept. of Defense, banking, manufacturing,
transportation, commercial aviation
• 1983 (C++ (FORMERLY “C WITH CLASSES”) CREATOR BJARNE
STROUSTRUP)
o An extension of C, with enhancements such as classes, virtual
functions, and templates.
o Primary Uses: Commercial application development, embedded
software, server/client applications, video games
o Used by: Adobe, Google Chrome, Mozilla Firefox, Microsoft
Internet Explorer
• 1983 OBJECTIVE-C (OBJECT-ORIENTED EXTENSION OF “C”)
CREATOR: BRAD COX AND TOM LOVE OF STEPSTONE
o Expanded on C, adding message-passing functionality based on
Smalltalk language.
o Used by: Apple’s OS X and iOS operating systems
• 1991 PYTHON (FOR BRITISH COMEDY TROUPE MONTY PYTHON)
CREATOR: GUIDO VAN ROSSUM OF CWI
o Created to support a variety of Programming styles and be fun to
use.
o Primary Uses: Web application, software development,
information security
o (Google, Yahoo, Spotify)
• 1993 RUBY (THE BIRTHSTONE OF ONE OF THE CREATOR’S
COLLABORATOR) CREATOR: YUKIHIRO MATSUMOTO
o Designed for productive and enjoyable programming. (Twitter,
Hulu, Groupon) Primary Uses: Web application development
• 1994 (JAVA CREATOR: JAMES GOSLING OF MICROSYSTEMS)
o Made for an interactive TV project. Cross-platform functionality.
Second most popular language (behind C).(Android OS/apps)
o Primary Uses: Network programming, web application
development, software development, Graphical User Interface
development
• 1994 (JAVA CREATOR: JAMES GOSLING OF MICROSYSTEMS)
By: Froilan G. Cantillo
Programming Logic and Design
BRIEF HISTORY OF PROGRAMMING LANGUAGE
12
• 1995 (PHP (“PERSONAL HOME PAGE”) CREATOR: RASMUS
LERDORF)
o For building dynamic web pages. Most widely used open-source
software by enterprises.
o Primary Uses: Building/maintaining dynamic web pages, server-
side development
o Used by: Facebook, Wikipedia, Digg, WordPress, Joomla
• 1995 (PHP (“PERSONAL HOME PAGE”) CREATOR: RASMUS
LERDORF)
• 1996 (JAVASCRIPT (FINAL CHOICE AFTER “MOCHA” AND
“LIVESCRIPT” CREATOR: BRENDAN EICH OF NETSCAPE)
o Created to extend web page functionality.
o Dynamic web pages’ use for form submission/validation,
interactivity, animations, user activity tracking, etc.
o Primary Uses: Dynamic web development, PDF documents, web
browsers, desktop widgets
o Used By: Gmail, Adobe Photoshop, Mozilla Firefox
• 1996 (JAVASCRIPT (FINAL CHOICE AFTER “MOCHA” AND
“LIVESCRIPT” CREATOR: BRENDAN EICH OF NETSCAPE)
By: Froilan G. Cantillo
Programming Logic and Design
HIERARCHY OF HIGH LEVEL LANGUAGES
13
High Level Languages
• High level languages are problem-orientated whereas low level
languages are machine-orientated.
• Problem-orientated means that the commands and the way the program
is structured are based on what the program will have to do rather than
the components of the computer it will be used with.
• This means that programs of high level languages are portable. These
programs can be written on one computer and then executed on
another.
• There are many types of high level languages, each is written to cope
with the demands of specific types of problems. E.g. some are designed
for scientific applications, manipulating databases, creating web pages
etc.
• There are 2 classified groups of high level languages
o Imperative
o Declarative
High Level
Programming
Languages
Imperative
Object
Oriented
Procedural
Declarative
Logic
Database
Query
Functional
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM
14
What is an algorithm?
• A set of steps to accomplish a task
• An algorithm is a sequence of unambiguous instruction
• An algorithm is a well-defined procedure that allows a computer to
solved a problem.
• An algorithm is a self-contained step-by-step set of operation to be
performed to solve a specific problem.
How to write an algorithm?
• Keep in mind that algorithm is a step-by-step process.
• Depending upon programming language, include syntax where
necessary.
• Include variables and their usage.
• If they are any loops, try to give sub number lists.
• Try to give go back to step number if loop or condition fails.
• Use jump statement to jump from one statement to another.
• Try to avoid unwanted raw data in algorithm.
• Use break and stop to terminate the process.
Characteristics of an Algorithm
• Unambiguous − Algorithm should be clear and unambiguous. Each of
its steps (or phases), and their inputs/outputs should be clear and must
lead to only one meaning.
• Input − An algorithm should have 0 or more well-defined inputs.
• Output − An algorithm should have 1 or more well-defined outputs, and
should match the desired output.
• Finiteness − Algorithms must terminate after a finite number of steps.
• Feasibility − Should be feasible with the available resources.
• Independent − An algorithm should have step-by-step directions, which
should be independent of any programming code.
Two forms of Algorithm:
• Pseudocode
• Flowchart
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM: PSEUDOCODE
15
Pseudocode
Pseudocode essentially is English with some defined rules of structure and
some keywords that make it appear a bit like program code. Some
guidelines for writing pseudocode are as follows.
Pseudocode Guidelines
• The keywords used for pseudocode in this document are:
1. for start and finish
BEGIN MAINPROGRAM, END MAINPROGRAM
2. for initialization
INITIALISATION, END INITIALISATION
3. for subprogram
BEGIN SUBPROGRAM. END SUBPROGRAM
4. for selection
IF. THEN, ELSE, ENDIF
5. for multi-way selection
CASEWHERE. OTHERWISE. ENDCASE
6. for pre-test repetition
WHILE. ENDWHILE
7. for post-test repetition
REPEAT. UNTIL
• Keywords are written in CAPITALS.
• Structural elements come in pairs,
o for every BEGIN there is an END
o for every IF there is an ENDIF. etc.
• Indenting is used to show structure in the algorithm.
• The names of subprograms are underlined.
o This means that when refining the solution to a problem. a word
in an algorithm can be underlined and a subprogram developed.
This feature enables the use of the 'top-down' development concept.
where details for a particular process need only be considered within the
relevant sub-routine.
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM: FLOW CHARTS
16
Flow Charts
• A drawing that uses symbols interconnected with lines to represent the
flow of information
• A process flow diagram that illustrates the successive steps in a
process, procedure, system or model.
• A pictorial representation showing/describing all of the steps of a
process being studied or even used to plan stages of a project. Flow
charts tend to provide people with a common language or reference
point when dealing with a project or process.
Purpose of Flow Charts
A Flowchart is used for:
1. Defining and analyzing processes
2. Building a step-by-step picture of the process for analysis, discussion,
or communication purposes
3. Defining, standardizing, or finding areas for improvement in a process
By visualizing the process, a flowchart can quickly help identify bottlenecks
or inefficiencies where the process can be streamlined or improved.
Basic flowcharting shapes and symbols
Flowcharts use special shapes to represent different types of actions or
steps in a process and Lines and arrows show the sequence of the steps,
and the relationships among them.
Start/End – The terminator symbol marks the starting or ending point the
system. It usually contains the word "Start" or "End."
Action or Process – A box can represent a single step ("add two cups of
flour), or and entire sub-process ("make bread") within a larger process.
Decision – A decision or branching point. Lines representing different
decisions emerge from different points of the diamond.
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM: FLOW CHARTS
17
Connector – Indicates that the flow continues where a matching symbol
containing the same letter) has been placed.
Flow Line – Lines indicate the sequence of steps and the direction of flow.
Input/ Output – Represents material or information entering or leaving the
system, such as customer order (input) or a product
Example of Flowchart
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM: FLOW CHARTS
18
Common Types of Flowcharts
There are four flowchart types that are particularly versatile. These four
common diagrams are great for describing business, manufacturing, or
administrative processes, seeing how an organization functions, or how
different departments work together.
1. The Process Flowchart
Illustrate How a Process Works or Plan a Project with a Process
Flowchart
A process flowchart or process flow diagram is probably the most
versatile of the four commonly used flowchart types because it can be
applied to virtually anything.
• Map out roles and responsibilities within an organization to gain
clarity.
• Draw up a proposal for a new process or project to understand its
scope and steps.
2. The Workflow Chart
Understand How Data and Documents Flow Within Your Organization
A workflow chart shows the way a business or process functions. This
type of workflow diagram can be used to:
• Train new employees
• Discover potential problem areas
• Clarify business operations by showing a high-level overview
3. The Swimlane Flowchart
Describe How Separate Departments, Processes or Employees
Interact
The swimlane flowchart comes in handy when you need to show
multiple flows of information side by side. Swimlane diagrams might
sound really similar to a workflow diagram, but the key here is that it
allows you to create different categories where activity takes place.
A swimlane flowchart or diagram is great for documenting a whole
process that interacts with different segments of an organization or
requires collaboration among different teams.
4. The Data Flowchart
See Where Data Flows In and Out of an Information System with a
Data Flow Diagram
A data flowchart or data flow diagram shows the way data is
processed. It comes in handy when you want to design or analyze a
system. Although most often used for software development and
design, it can be used to analyze any type of information flow, like how
information moves through a business.
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM: FLOW CHARTS
19
Steps for creating a flowchart are:
1. Familiarize the participants with the flowchart symbols
2. Brainstorm major process tasks. Ask questions such as "What really
happens next in the process? ", "Does a decision need to be made
before the next step? ", or What approvals are required before moving
on to the next task?"
3. 3Draw the process flowchart using the symbols on a flip chart or
overhead transparency. Every process will have a start and an end
(shown by elongated circles). All processes will have tasks and most
will have decision points (shown by a diamond).
4. Analyze the flowchart for such items as:
• Time-per-event (reducing cycle time) 0 Process repeats (preventing
rework)
• Duplication of effort (identifying and eliminating duplicated tasks)
• Unnecessary tasks (eliminating tasks that are in the process for no
apparent reason)
• Value-added versus non-value-added tasks
CONSTRUCTION/INTERPRETATION tip for a flow chart.
• Define the boundaries of the process clearly.
• Use the simplest symbols possible.
• Make sure every feedback loop has an escape.
• There is usually only one output arrow out of a process box. Otherwise,
it may require a decision diamond.
• Analyze flow chart of actual process.
• Analyze flow chart of best process.
• Compare both charts, looking for areas where they are different. Most of
the time, the stages where differences occur is considered to be the
problem area or process.
• Take appropriate in-house steps to correct the differences between the
two separate flows.
By: Froilan G. Cantillo
Programming Logic and Design
ALGORITHM: FLOW CHARTS
20
Tips for Effective Flowcharts
1. Label each flowchart with a title identifying the process that it
illustrates. (For example: Entry Process").
2. Clearly indicate the starting and ending points of the process, using the
standard terminator symbols.
3. Keep the direction of flow consistent. Avoid confusion by keeping your
flow lines moving from top to bottom and left to right. Don't reverse the
direction in the chart unless the flow reverses itself in reality.
4. Break the steps down to a consistent level of detail. Don't include trivial
sub-steps of one task while treating another equivalent task as a
whole. If one step or task needs to be analyzed in detail, make a
separate chart illustrating that sub-process.
• You can hyperlink the shape representing a sub-process that,
illustrates it, allowing users to "drill down" for more detail.)
5. Avoid crossing flow lines. In a well-designed chart, flow lines will not
cross each other. By rearranging a chart, you can usually get rid of
crossed lines. If two lines must cross, use a "bridge" (also known as a
"line hop") to show that the lines do not intersect.
6. Make sure there are at least two no outcomes from every decision
diamond.
7. Label your flowchart components. Use active verbs to label activity
steps and questions to label decisions. Clearly label the form a
decision diamond in terms that answer the question.
Flowchart and Pseudocode
By: Froilan G. Cantillo
Programming Logic and Design
DATA TYPES
21
Data Types
• A data type defines a set of values and a set of operation on those
values. A C++ program may need to required different type of data.
Each type required different type of memory.
• It indicates the type of data that can be store in a variable
• There are three basic data type.
o Character
o Integer
o Float
Character data type
• This data type is used to store character values.
• Characters may include letters, digits and punctuation character. It take
one byte in memory i.e. ‘a’ and ‘@’ etc.
• Represented by the “char” data type.
• The “short” data type is the same size as “char” usually one byte.
• The character variable can store only one character
• The Character range is “-128 to 127”
We can declare it as below.
Char a= ‘A’
Char f= ‘B’
Char z= ‘D’ etc
Integer data type:
• A numeric value with no fraction is called integer data. It include both
positive and negative values.
• Represented by “int”
• Int range –32,768 to 32,767
• Some example of integer value are 56 and -12
• Int size is ‘2’ bytes
• Long int size ‘4’ bytes
We can declare it as below.
Int a=20;
Int b=40;
Int c=30;
By: Froilan G. Cantillo
Programming Logic and Design
DATA TYPES
22
Type of Integer data type
Int data type
• To store integer values and takes two byte in memory. i.e. int num;
Long int data type
• To store large integer value. It has greater range and takes ‘4’ bytes in
memory. i.e. long int num;
Float data type:
• A numeric value with fraction is called real data type / float data type. It
include both
• Positive and negative values. i.e. 12.4 and -34.3
• This data type are represented by “float”.
• Float number are declared as
Float a= “40.00”
Float b= “23.04”
Float c= “10.3” etc.
Type of float
• Float data type
o This data type is used to store real values and
o Takes ‘4’ bytes in memory. i.e. Float num;
• Double data type
o It has great range as compared to float and takes ‘8’ byte in
memory. i.e. Double num;
By: Froilan G. Cantillo
Programming Logic and Design
DATA TYPES
23
Variable
• A quantity whose values may change during the execution of the
program is called variable.
• It may be a numeric or non-numeric quantity
• It represented by an identifier called variable name
• A variable represents a memory location in the computer memory. Data
is store into the memory location. The name of memory location or
variable name remains fixed during the execution of the program but the
data store in that location may change from time to time
Variable Declaration
• A variable is case sensitive, that is, uppercase variables are treated
differently
• Variable “SUM” is different from variable “sum”
• Variable “NetPay” is different from variable “NETpay”
Rules for variable Declaration
• Variable may include letter, number and underscore (_)
• The first latter of the variable must be character or underscore.
• Blank spaces special symbols, commas are not used
• A variable can be ‘31’ character long for many compilers
• Key word are not used as variable name.
Variable Declaration
• The process of specifying the name and its data type is called variable
declaration
• All variables that are used in a program are declared using variable
declaration statement.
• When a variable is declared a certain number of bytes in the memory
are allocated to the variable name.
Variable Initialization
• The process of assigning a value to a variable at the time of declaration
is known as variable initialization.
• The equal (=) is used to initialize a variable.
• Variable name is given on the left side and value is given on the right
side of equal sign.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc ARDUINO
24
Introduction
Arduino is an open-source electronics platform based on easy-to-use
hardware and software. Arduino boards are able to read inputs - light on a
sensor, a finger on a button, or a Twitter message - and turn it into an
output - activating a motor, turning on an LED, publishing something
online. You can tell your board what to do by sending a set of instructions
to the microcontroller on the board.
What is Arduino?
• Arduino is an open-source electronics platform based on easy-to-use
hardware and software.
• Arduino boards are able to read inputs and turn it into an output.
• You can tell your board what to do by sending a set of instructions to the
microcontroller on the board.
• Arduino was born at the Ivrea Interaction Design Institute
• Easy tool for fast prototyping
• Aimed at students without a background in electronics and
programming.
Why Arduino?
• Arduino has been used in thousands of different projects and
applications.
• The Arduino software is easy-to-use for beginners, yet flexible enough
for advanced users.
• It runs on Mac, Windows, and Linux. Teachers and students use it to
build low-cost scientific instruments or to get started with programming
and robotics.
• Arduino is a key tool to learn new things.
• Anyone can start tinkering just following the step-by-step instructions of
a kit, or sharing ideas online with other members of the Arduino
community.
Inexpensive – Arduino boards are relatively inexpensive compared to
other microcontroller platforms.
Cross-platform – The Arduino Software (IDE) runs on Windows,
Macintosh OSX, and Linux operating systems. Most microcontroller
systems are limited to Windows.
Simple, clear programming environment – The Arduino Software (IDE)
is easy-to-use for beginners, yet flexible enough for advanced users to
take advantage of as well.
Open source and extensible software – The Arduino software is
published as open source tools, available for extension by experienced
programmers.
Open source and extensible hardware – The plans of the Arduino
boards are published under a Creative Commons license, so experienced
circuit designers can make their own version of the module, extending it
and improving it.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO
25
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO: UNO
26
Arduino Uno
Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM,
32KB flash storage)
Features: 14 digital I/O pins, 6 analog input pins, removable
microcontroller
Form Factor: 2.7” x 2.1” rectangle
The Arduino Uno is the most “standard” Arduino board currently on the
market, and is probably the best choice for beginners just getting started
with the platform. The board is compatible with more shields (add-on
boards) than other models.
The Uno’s main limitation is the ATmega328 chip, which doesn’t have a lot
of SRAM or flash memory. That limit’s the kinds of programs you can load
on the chip – if your project involves a display or otherwise needs to store
and use any form of images or audio data, 2KB of memory probably isn’t
going to be enough.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO : MEGA
27
Arduino Mega
Processor: ATmega2560 (8-bit CPU, 16MHz clock speed, 8KB SRAM,
256KB flash storage)
Features: 54 digital I/O pins (15 PWM), 16 analog input pins, 4 UARTs, 16
MHz crystal oscillator
Form Factor: 101.52mm x 53.3mm rectangle
The Mega is a microcontroller board based on the ATmega2560. The
Mega is compatible with most shields designed for the Arduino
Duemilanove or Diecimila. It is intended for comparatively bigger projects
requiring a large number of input and output pins.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO : NANO
28
Arduino Nano
Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM,
32KB flash storage)
Features: 22 digital I/O pins, 8 analog input pins
Form Factor: 18mm x 45mm rectangle
The Arduino Nano is a small, complete, and breadboard-friendly board
based on the ATmega.328 (Arduino Nano 3.x). It has more or less the
same functionality of the Arduino Duemilanove, but in a different package.
It lacks only a DC power jack, and works with a mini-B USB cable instead
of a standard one.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO: MINI
29
Arduino Mini
Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM,
32KB flash storage)
Features: 14 digital I/O pins, 8 analog input pins, 16 MHz crystal oscillator
Form Factor: 30mm x 18mm rectangle
The Arduino Mini is a small microcontroller board originally based on the
ATmega168, but now supplied with the 328 (datasheet), intended for use
on breadboards and when space is at a premium.
The new Mini (revision 05) has a new package for the ATmega, which
enable all components to be on the top of the board. It also has an
onboard reset button.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO: LEONARDO
30
Arduino Leonardo
Processor: ATmega32u4 (8-bit CPU, 16MHz clock speed, 2KB SRAM,
32KB flash storage)
Features: 20 digital I/O pins (7 PWM), 12 of which can be used as analog
inputs, native USB support
Form Factor: 68.6mm x 53.3mm rectangle
The Leonardo is, essentially, a slight upgrade to the Uno. It looks a lot like
the Uno, but it features a soldered-on ATmega32u4 microcontroller with a
tiny bit more memory. The main advantage of the ATmega32u4 isn’t the
extra SRAM, though, it’s the chip’s built-in USB compatibility. This allows
the Leonardo to interface with a PC, which sees it as a generic mouse or
keyboard. It also features a few extra analog input pins.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO: DUE
31
Arduino Due
Processor: Atmel SAM3X8E ARM Cortex-M3 (32-bit CPU, 84MHz clock
speed, 96KB SRAM, 512KB flash storage)
Features: 54 digital I/O pins (12 PWM), 12 analog input pins, 2 analog
output pins, native USB port
Form Factor: 101.52mm x 53.3mm rectangle
One of the newest Arduino boards, the Due is the heavy-hitter of the
family, packing a 32-bit ARM processor that handily outclasses any of the
processors found in other Arduino boards. The Due is primarily for more
complicated projects that can make sure of its muscular processor, or that
need more I/O pins than are found on the smaller Arduino boards. That
said, the Due is substantially bigger and more expensive than the Uno or
Leonardo, so consider whether you really need the extra power before
making a purchase.
One drawback to the Due is that it operates at 3.3 volts, which is different
than the 5 volts that most other Arduino boards operate at. That limits the
add-on hardware that’s compatible with the Arduino Due – if an add-on
board tries to send a 5 volt signal to the Due’s I/O pins, it could damage
the microcontroller.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc TYPES OF ARDUINO LILYPAD
32
Arduino Lilypad
Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM,
32KB flash storage)
Features: 14 digital I/O pins, 6 analog input pins
Form Factor: 2” diameter circle
The Lilypad is an Arduino board specifically designed for wearable
devices. Its circular shape and standoff-less I/O pins are designed to make
it easy to sew the Lilypad into fabric-based projects.
The hardware on a standard LilyPad board is basically the same as on
and Arduino Uno. There are a number of other LilyPad options available
as well, including the LilyPad Arduino USB, which feature’s the Leonardo’s
ATmega32u4 chip, the Lilypad Arduino Simple, which has fewer I/O
connections than the basic model, and the LilyPad Arduino SimpleSnap,
which can be snapped into and out of projects, so they can be safely
washed.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc PARTS OF ARDUINO UNO
33
1 – Power USB
Arduino board can be powered by using the USB cable from your
computer. All you need to do is connect the USB cable to the USB
connection (1).
2 – Power (Barrel Jack)
Arduino boards can be powered directly from the AC mains power supply
by connecting it to the Barrel Jack (2).
3 – Voltage Regulator
The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and
other elements.
4 – Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does
Arduino calculate time? The answer is, by using the crystal oscillator. The
number printed on top of the Arduino crystal is 16.000H9H. It tells us that
the frequency is 16,000,000 Hertz or 16 MHz.
5,17 – Arduino Reset
You can reset your Arduino board, i.e., start your program from the
beginning. You can reset the UNO board in two ways. First, by using the
reset button (17) on the board. Second, you can connect an external reset
button to the Arduino pin labelled RESET (5).
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc PARTS OF ARDUINO UNO
34
6,7,8,9 – Pins (3.3, 5, GND, Vin)
• 3.3V (6) − Supply 3.3 output volt
• 5V (7) − Supply 5 output volt
• Most of the components used with Arduino board works fine with 3.3
volt and 5 volt.
• GND (8)(Ground) − There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
• Vin (9) − This pin also can be used to power the Arduino board from an
external power source, like AC mains power supply.
10 – Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These
pins can read the signal from an analog sensor like the humidity sensor or
temperature sensor and convert it into a digital value that can be read by
the microprocessor.
11 – Main Microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as
the brain of your board. The main IC (integrated circuit) on the Arduino is
slightly different from board to board. The microcontrollers are usually of
the ATMEL Company. You must know what IC your board has before
loading up a new program from the Arduino IDE. This information is
available on the top of the IC. For more details about the IC construction
and functions, you can refer to the data sheet.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc PARTS OF ARDUINO UNO
35
12 – ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino
consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often
referred to as an SPI (Serial Peripheral Interface), which could be
considered as an "expansion" of the output. Actually, you are slaving the
output device to the master of the SPI bus.
13 – Power LED indicator
This LED should light up when you plug your Arduino into a power source
to indicate that your board is powered up correctly. If this light does not
turn on, then there is something wrong with the connection.
14 – TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive).
They appear in two places on the Arduino UNO board. First, at the digital
pins 0 and 1, to indicate the pins responsible for serial communication.
Second, the TX and RX led (13). The TX led flashes with different speed
while sending the serial data. The speed of flashing depends on the baud
rate used by the board. RX flashes during the receiving process.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc PARTS OF ARDUINO UNO
36
15 – Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide
PWM (Pulse Width Modulation) output. These pins can be configured to
work as input digital pins to read logic values (0 or 1) or as digital output
pins to drive different modules like LEDs, relays, etc. The pins labeled “~”
can be used to generate PWM.
16 – AREF
AREF stands for Analog Reference. It is sometimes, used to set an
external reference voltage (between 0 and 5 Volts) as the upper limit for
the analog input pins.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc ARDUINO IDE
37
Arduino Software
You can download the Arduino IDE (The program used to write code and
uploading it to Arduino boards) from https://www.arduino.cc/en/software
Connect your Arduino Uno to your PC via USB Cable
Select your board
• Tools → Board: “Arduino/Ginuino Uno” → Arduino/Ginuino Uno
Select your serial port
• Tools → Port
Compile:
• Compile the sketch after writing the code
• Check your codes for error
Upload:
• Upload the program to the configured Arduino board
New Open Save
Serial Monitor
Name of Sketch
Verify: Compile Sketch
Upload: Upload the
program to the board
Code Area
Messages / Error
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc STRUCTURE: SKETCH
38
The basic code structure of Arduino programming is simple and is
composed of two parts:
1. Setup
2. Loop
The code you write for your Arduino are known as sketches. They are
written in C++.
Every sketch needs two void type functions, setup() and loop(). A void type
function doesn’t return any value.
The setup() method is ran once, just after the Arduino is powered up, and
the loop() method is ran continuously afterwards.
The setup() is where you want to do any initialization steps, and in loop()
you want to run the code you want to run over and over again.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc
if Statement
‘if’ statements test whether a certain condition has been reached, such as
whether a number has reaches a certain value, and if true, executes the
statements in the brackets. The code in the brackets is skipped if the
statement is false.
The syntax for if statement is:
void loop(){
if(somevariable <testcondition> value){
doSomething;
}
}
The above condition test compares somevariable with a value. If this
condition is satisfied, then the code inside the parenthesis (dosomething)
is executed.
STRUCTURE: CONTROL STRUCTURE
39
If…else
The ‘if…else’ statements allow either/or statements to be made. These
statements can be used when more than one courses of action are
possible, as determined by the variable or value being tested. The syntax
for ‘if…else’ implementation is:
void loop(){
if(inputPin == HIGH){
doThing1;
}else{
doThing2;
}
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc STRUCTURE: CONTROL STRUCTURE
40
If…else if ladder
If more than two courses of action are possible, then the ‘if…else if’ ladder
is to be used, which allows the choice and execution of one statement
from an infinite number of possibilities. The syntax is as follows:
void loop(){
if(inputPin <testcondition> value1){
doThing1;
}else if(inputPin <testcondition> value2){
doThing2;
}else if(inputPin <testcondition> value3){
doThing3;
}else{
doThing4;
}
}
for Statement
The ‘for’ statement is used to repeat a statement of a block of statements
a specified number of times. The arguments for the ‘for’ loop consists of:
1. Initialization. This initializes a variable with a specified initial value.
2. Test condition. This condition is tested for every loop and the ‘for’
statement stops looping when this condition does not hold true.
3. Increment/decrement expression. This expression operates on the
initialized variable.
The syntax for the ‘for’ loop is as follows:
void loop(){
for(initialization; condition; increment/decrement
expression){
doSomething;
}
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc STRUCTURE: CONTROL STRUCTURE
41
while Loop
The ‘while’ loop will loop continuously and infinitely, until the expression
inside the brackets become false. If the tested variable of value is not
changed, the loop will go on for infinity.
void loop(){
while(variable <test condition> value){
doSomething;
}
}
do…while Loop
The ‘do…while’ class works in a similar manner to the ‘while’ class, the
only difference being, that, in the ‘do…while’ class the condition is tested
at the bottom of the loop, making sure the loops is carried out at least
once.
void loop(){
do{
doSomething;
}while(variable <test condition> value)
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc CONSTANT: HIGH/LOW
42
HIGH/LOW
These are constraints used to signify 0V or 5V (logic 0 or 1) when writing
or reading from digital pins. In the following example, if the pin value on pin
11 is HIGH, the pin value on pin 12 is set as HIGH.
void setup(){
pinMode(12, OUTPUT);
pinMode(11, INPUT);
}
void loop(){
if(digitalRead(11) == HIGH){
digitalWrite(12, HIGH);
}
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: DIGITAL INPUT/OUTPUT
43
pinMode
This command is used to set pins as input or output in the Setup().
Arduino digital pins are set to input by default, hence there is no need to
specifically declare them as inputs using pinMode(). Pins configured as
inputs are said to be in a high impedance state.
The syntax for declaring pins using pinMode() is as follows:
void setup(){
pinMode(11, INPUT); //Sets pin 11 as input
pinMode(12, OUTPUT); //Sets pin 12 as output
}
void loop(){
}
For convenience there are 20k ohm pull up resistors built into the ATmega
chip which can be accessed through software in the following manner:
void setup(){
pinMode(11, INPUT); //Sets pin 11 as input
digitalWrite(11, HIGH); //Turns on 20k-ohms
//pullup resistor
}
void loop(){
}
Pins set as OUTPUT are said to be in a low resistance state and can
supply 40mA of current to connected circuits or components.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: DIGITAL INPUT/OUTPUT
44
digitalRead
This function is used to read the digital value of a pin. The result is either
HIGH or LOW.
The syntax is as follows:
void setup(){
pinMode(11, INPUT); //Sets pin 11 as input
}
void loop(){
int value = digitalRead(11); //Sets variable value
//equal to the input pin
}
digitalWrite
Sets the pins on or off, by giving them either HIGH or LOW output. The
function takes two parameters, the pin number and either HIGH or LOW,
as follows:
void setup(){
pinMode(12, OUTPUT); //Sets pin 12 as output
}
void loop(){
digitalWrite(12, HIGH); //Sets value of pin 12 as HIGH
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: ANALOG INPUT/OUTPUT
45
analogRead
This function reads the value from a specified analogue pin and returns a
value between 0-1023. It only works on the six analogue pins from 0-5.
The syntax is as follows:
void setup(){
pinMode(0, INPUT); //Sets pin 0 as input
}
void loop(){
int value = analogRead(0); //Reads the analogue value
//between 0-1023) of the
//analog pin 0
}
analogWrite
This function is used to give an analog output. Analog outputs can only be
given to pins 3, 5, 6, 9, 10 and 11 on the Uno. Values between 0-255 can
be given to the analog pins.
The syntax is as follows:
void setup(){
pinMode(3, OUTPUT); //Sets pin 3 as output
}
void loop(){
analogWrite(3, value); //Sets the value of analog pin
//3 equal to value (must be
//from 0-255)
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: TIME
46
millis()
Acts like a clock and returns the number of milliseconds that have passed
since the Arduino board began running the current program as an
unsigned long int. The clock resets to zero after about 9 hours:
void loop(){
int timeelapsed = millis(); //Sets the variable
//timelapsed to the number
//of milliseconds passed
//since program execution
}
micros()
Similar to millis(), it acts like a clock and returns the number of
microseconds that have passed since Arduino board began running the
current program as an unsigned long int. This number will overflow and
become zero again after approximately 70 minutes:
Pins set as OUTPUT are said to be in a low resistance state and can
supply 40mA of current to connected circuits or components.
unsigned long time;
void setup()(
Serial.begin(9600);
}
void loop()
Serial.print(“Time: ");
time = micros(); //prints time since program started
Serial.println(time); //wait a second so as not to
//send massive amount of data
delay(1000);
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: TIME
47
delay(ms)
Pauses the program for the specified amount of time. The arguments take
time duration in milliseconds:
void loop()(
digitalWrite(11, HIGH);
delay(1000); //Pauses the program for 1000
//millisecond or 1 second
}
delayMicroseconds(us)
Here, ‘us’ is the time in microseconds. Similar to delay(ms), this function
pauses the program for the specified amount of time. The arguments take
time duration in microseconds as an unsigned int:
int outPin = 8; //digital pin 8
void setup(){
pinMode(outPin, OUTPUT); //Sets the digital pin as
//output
}
void loop(){
digitalWrite(outPin, HIGH); //Sets the pin on
delayMicroseconds(100); //Pauses for 100
//microseconds
digitalWrite(outPin, LOW); //Sets the pin off
delayMicroseconds(100); //Pauses for 100
//microseconds
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: MATH
48
min(x,y)
Returns the smaller of the two values passed into the function as
arguments.
void loop(){
int x,y;
int smaller_num = min(x,y); //Sets smaller_num equal
//to x or y depending upon
//whichever is smaller
}
max(x,y)
Returns the larger of the two values passed into the function as
arguments.
void loop(){
int x,y;
int larger_num = max(x,y); //Sets larger_num equal to
//x or y depending upon
//whichever is larger
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: RANDOM NUMBERS
49
randomSeed(seed)
Sets a value as a starting point before the random() function. The seed
can be any variable, input, constraints or other functions. Must be used
before the random function.
void loop(){
randomSeed(analogRead(3)); //Uses the analog value at
//pin 3 to set a starting
//point for the random
//function
}
random(min,max)
This function helps in generating pseudo-random values for the given
range in the arguments. The function randomSeed(seed) must be used
before using this function.
void loop(){
int value_1;
int value_2;
rendomSeed(analogRead(3));
value_l = random(100); //Sets value_l equal to any
//random number between 0 and
//100
value_2 = random(50,100): //Sets value_2 equal to any
//random number between SO
//and 100
}
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc FUNCTIONS: COMMUNICATION
50
Serial.begin()
This function opens up the USB port for serial communication and also
sets the baud rate. Typical baud rate for serial communication with
computer is 9600bps.
void setup(){
Serial.begin(9600); //Opens the serial port and sets
//the band rate at 9600bps
}
Serial.println()
Prints the value passed into the brackets on to the Serial Monitor.
void loop(){
int value = 100;
Serial.println(value); //Prints value on to the Serial
//Monitor followed by a return
//carry and line feed
}
Click the encircled link to bring up the Serial Monitor.
By: Froilan G. Cantillo
Programming Logic and Design
arduino.cc REFERENCE
51
https://www.arduino.cc/
https://en.wikipedia.org/wiki/Arduino
https://www.slideshare.net/

Mais conteúdo relacionado

Mais procurados

Troubleshooting methods of computer peripherals
Troubleshooting methods of computer peripheralsTroubleshooting methods of computer peripherals
Troubleshooting methods of computer peripheralsDevyani Chaudhari
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerAbha Damani
 
What is a Server
What is a ServerWhat is a Server
What is a ServerKuwait10
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Arslan Hussain
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingNSU-Biliran Campus
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1deathful
 
Generation of computer languages
Generation of computer languagesGeneration of computer languages
Generation of computer languageskitturashmikittu
 
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMSDESIGN AND IMPLEMENTATIONOPERATING SYSTEMSDESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION sathish sak
 
Assembly language programming
Assembly language programmingAssembly language programming
Assembly language programminghimhk
 
computer languages
computer languagescomputer languages
computer languagesRajendran
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingSangheethaa Sukumaran
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2REHAN IJAZ
 

Mais procurados (20)

Introduction to programming languages
Introduction to programming languagesIntroduction to programming languages
Introduction to programming languages
 
Computer and network security
Computer and network securityComputer and network security
Computer and network security
 
Troubleshooting methods of computer peripherals
Troubleshooting methods of computer peripheralsTroubleshooting methods of computer peripherals
Troubleshooting methods of computer peripherals
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
What is a Server
What is a ServerWhat is a Server
What is a Server
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Computer Security
Computer SecurityComputer Security
Computer Security
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1
 
ICT Model Questions
ICT Model Questions ICT Model Questions
ICT Model Questions
 
Generation of computer languages
Generation of computer languagesGeneration of computer languages
Generation of computer languages
 
Data Backup (IT) Lecture Slide # 5
Data Backup (IT) Lecture Slide # 5Data Backup (IT) Lecture Slide # 5
Data Backup (IT) Lecture Slide # 5
 
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMSDESIGN AND IMPLEMENTATIONOPERATING SYSTEMSDESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
 
Assembly language programming
Assembly language programmingAssembly language programming
Assembly language programming
 
computer languages
computer languagescomputer languages
computer languages
 
Computer maintenance-and-repair
Computer maintenance-and-repairComputer maintenance-and-repair
Computer maintenance-and-repair
 
Programming Design Tools
Programming Design ToolsProgramming Design Tools
Programming Design Tools
 
COMPUTER SYSTEM
COMPUTER SYSTEMCOMPUTER SYSTEM
COMPUTER SYSTEM
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 

Semelhante a Program Logic and Design

Introduction to computer programming
Introduction to computer programming Introduction to computer programming
Introduction to computer programming VanessaBuensalida
 
introductiontocomputerprogramming.pptx
introductiontocomputerprogramming.pptxintroductiontocomputerprogramming.pptx
introductiontocomputerprogramming.pptxHazardRhenz1
 
introductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptxintroductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptxummeafruz
 
Introductiontocomputerprogramming 140713205433-phpapp02
Introductiontocomputerprogramming 140713205433-phpapp02Introductiontocomputerprogramming 140713205433-phpapp02
Introductiontocomputerprogramming 140713205433-phpapp02Lanie Plecerda
 
Introductiontocomputerprogramming 140713205433-phpapp02 (1)
Introductiontocomputerprogramming 140713205433-phpapp02 (1)Introductiontocomputerprogramming 140713205433-phpapp02 (1)
Introductiontocomputerprogramming 140713205433-phpapp02 (1)Lanie Plecerda
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresNisarg Amin
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptxPmarkNorcio
 
Algorithm and flowchart(1)
Algorithm and flowchart(1)Algorithm and flowchart(1)
Algorithm and flowchart(1)Suneel Dogra
 
Lec21&22.pptx programing language and there study
Lec21&22.pptx programing language and there studyLec21&22.pptx programing language and there study
Lec21&22.pptx programing language and there studysamiullahamjad06
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FITRaj vardhan
 
Lecture_1_Introduction_to_Programming.pptx
Lecture_1_Introduction_to_Programming.pptxLecture_1_Introduction_to_Programming.pptx
Lecture_1_Introduction_to_Programming.pptxChewe Lulembo
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugageseShikshak
 
Programming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages ConceptsProgramming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages Conceptsimtiazalijoono
 

Semelhante a Program Logic and Design (20)

sege.pdf
sege.pdfsege.pdf
sege.pdf
 
Introduction to computer programming
Introduction to computer programming Introduction to computer programming
Introduction to computer programming
 
programming.pptx
programming.pptxprogramming.pptx
programming.pptx
 
introductiontocomputerprogramming.pptx
introductiontocomputerprogramming.pptxintroductiontocomputerprogramming.pptx
introductiontocomputerprogramming.pptx
 
introductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptxintroductiontocomputerprogramming-140713205433-phpapp02.pptx
introductiontocomputerprogramming-140713205433-phpapp02.pptx
 
Introductiontocomputerprogramming 140713205433-phpapp02
Introductiontocomputerprogramming 140713205433-phpapp02Introductiontocomputerprogramming 140713205433-phpapp02
Introductiontocomputerprogramming 140713205433-phpapp02
 
Introductiontocomputerprogramming 140713205433-phpapp02 (1)
Introductiontocomputerprogramming 140713205433-phpapp02 (1)Introductiontocomputerprogramming 140713205433-phpapp02 (1)
Introductiontocomputerprogramming 140713205433-phpapp02 (1)
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwares
 
Programming languages.pptx
Programming languages.pptxProgramming languages.pptx
Programming languages.pptx
 
Lesson 2.pptx
Lesson 2.pptxLesson 2.pptx
Lesson 2.pptx
 
Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
 
Algorithm and flowchart(1)
Algorithm and flowchart(1)Algorithm and flowchart(1)
Algorithm and flowchart(1)
 
Languages in computer
Languages in computerLanguages in computer
Languages in computer
 
Lec21&22.pptx programing language and there study
Lec21&22.pptx programing language and there studyLec21&22.pptx programing language and there study
Lec21&22.pptx programing language and there study
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FIT
 
Lecture_1_Introduction_to_Programming.pptx
Lecture_1_Introduction_to_Programming.pptxLecture_1_Introduction_to_Programming.pptx
Lecture_1_Introduction_to_Programming.pptx
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Programming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages ConceptsProgramming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages Concepts
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
 

Mais de Froilan Cantillo

Living in the IT Era - Lesson 9.pptx
Living in the IT Era - Lesson 9.pptxLiving in the IT Era - Lesson 9.pptx
Living in the IT Era - Lesson 9.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 7.pptx
Living in the IT Era - Lesson 7.pptxLiving in the IT Era - Lesson 7.pptx
Living in the IT Era - Lesson 7.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 2.pptx
Living in the IT Era - Lesson 2.pptxLiving in the IT Era - Lesson 2.pptx
Living in the IT Era - Lesson 2.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 2.2.pptx
Living in the IT Era - Lesson 2.2.pptxLiving in the IT Era - Lesson 2.2.pptx
Living in the IT Era - Lesson 2.2.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 8.pptx
Living in the IT Era - Lesson 8.pptxLiving in the IT Era - Lesson 8.pptx
Living in the IT Era - Lesson 8.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 5.pptx
Living in the IT Era - Lesson 5.pptxLiving in the IT Era - Lesson 5.pptx
Living in the IT Era - Lesson 5.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 6.pptx
Living in the IT Era - Lesson 6.pptxLiving in the IT Era - Lesson 6.pptx
Living in the IT Era - Lesson 6.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 3.pptx
Living in the IT Era - Lesson 3.pptxLiving in the IT Era - Lesson 3.pptx
Living in the IT Era - Lesson 3.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 5.0.pptx
Living in the IT Era - Lesson 5.0.pptxLiving in the IT Era - Lesson 5.0.pptx
Living in the IT Era - Lesson 5.0.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 4.pptx
Living in the IT Era - Lesson 4.pptxLiving in the IT Era - Lesson 4.pptx
Living in the IT Era - Lesson 4.pptxFroilan Cantillo
 
Living in the IT Era - Lesson 1.pptx
Living in the IT Era - Lesson 1.pptxLiving in the IT Era - Lesson 1.pptx
Living in the IT Era - Lesson 1.pptxFroilan Cantillo
 
01_Introduction to living in the it era
01_Introduction to living in the it era01_Introduction to living in the it era
01_Introduction to living in the it eraFroilan Cantillo
 

Mais de Froilan Cantillo (13)

Living in the IT Era - Lesson 9.pptx
Living in the IT Era - Lesson 9.pptxLiving in the IT Era - Lesson 9.pptx
Living in the IT Era - Lesson 9.pptx
 
Living in the IT Era - Lesson 7.pptx
Living in the IT Era - Lesson 7.pptxLiving in the IT Era - Lesson 7.pptx
Living in the IT Era - Lesson 7.pptx
 
Living in the IT Era - Lesson 2.pptx
Living in the IT Era - Lesson 2.pptxLiving in the IT Era - Lesson 2.pptx
Living in the IT Era - Lesson 2.pptx
 
Living in the IT Era - Lesson 2.2.pptx
Living in the IT Era - Lesson 2.2.pptxLiving in the IT Era - Lesson 2.2.pptx
Living in the IT Era - Lesson 2.2.pptx
 
Living in the IT Era - Lesson 8.pptx
Living in the IT Era - Lesson 8.pptxLiving in the IT Era - Lesson 8.pptx
Living in the IT Era - Lesson 8.pptx
 
Living in the IT Era - Lesson 5.pptx
Living in the IT Era - Lesson 5.pptxLiving in the IT Era - Lesson 5.pptx
Living in the IT Era - Lesson 5.pptx
 
Living in the IT Era - Lesson 6.pptx
Living in the IT Era - Lesson 6.pptxLiving in the IT Era - Lesson 6.pptx
Living in the IT Era - Lesson 6.pptx
 
Living in the IT Era - Lesson 3.pptx
Living in the IT Era - Lesson 3.pptxLiving in the IT Era - Lesson 3.pptx
Living in the IT Era - Lesson 3.pptx
 
Living in the IT Era - Lesson 5.0.pptx
Living in the IT Era - Lesson 5.0.pptxLiving in the IT Era - Lesson 5.0.pptx
Living in the IT Era - Lesson 5.0.pptx
 
Living in the IT Era - Lesson 4.pptx
Living in the IT Era - Lesson 4.pptxLiving in the IT Era - Lesson 4.pptx
Living in the IT Era - Lesson 4.pptx
 
Living in the IT Era - Lesson 1.pptx
Living in the IT Era - Lesson 1.pptxLiving in the IT Era - Lesson 1.pptx
Living in the IT Era - Lesson 1.pptx
 
Introduction to AutoCAD
Introduction to AutoCADIntroduction to AutoCAD
Introduction to AutoCAD
 
01_Introduction to living in the it era
01_Introduction to living in the it era01_Introduction to living in the it era
01_Introduction to living in the it era
 

Último

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Program Logic and Design

  • 1. Programming By: Froilan G. Cantillo 1 Computer Engineering Department President Ramon Magsaysay State University Logic Design and
  • 2. By: Froilan G. Cantillo Programming Logic and Design INTRODUCTION OF COMPUTER PROGRAMMING 2 Computer Program – Is a list of instructions that the computer machine follows to properly accept input, correctly process them and present the results in the most understandable way. Computer Programming – is considered to be an art and at the same time a science. It is an art because there is no standard way to interpret a problem and solve it using a standard form of programming procedures and styles. It is fast becoming a science because standard programming practice is starting to be adopted. Programs fall into two major classes: • Application Programs – application program is one that carries out some function directly for a user, such as word processing or game- playing. • Operating Systems – operating system is a program that manages the computer and the various resources and devices connected to it, such as RAM (random access memory), hard drives, monitors, keyboards, printers, and modems, so that they may be used by other programs. A programmer uses another type of program called a text editor to write the new program in a special notation called a programming language. With the text editor, the programmer creates a text file, which is an ordered list of instructions, also called the program source file. The individual instructions that make up the program source file are called source code. At this point, a special applications program translates the source code into machine language, or object code — a format that the operating system will recognize as a proper program and be able to execute. Three types of applications programs translate from source code to object code: • Compilers – Computer software that translates (compiles) source code written in a high-level language (e.g., C++) into a set of machine- language instructions that can be understood by a digital computer's CPU. Compilers are very large programs, with error-checking and other abilities • Interpreters – Is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution: o Parse the source code and perform its behavior directly; o Translate source code into some efficient intermediate representation and immediately execute this; o Explicitly execute stored precompiled code made by a compiler which is part of the interpreter system • Assemblers – Is a program that converts assembly language into machine code. It takes the basic commands and operations from assembly code and converts them into binary code that can be recognized by a specific type of processor. Assemblers are similar to compilers in that they produce executable code
  • 3. By: Froilan G. Cantillo Programming Logic and Design INTRODUCTION OF COMPUTER PROGRAMMING 3 Computer is composed of: 1. CPU (Central Processing Unit) – this is where all mathematical and logical forms of processing are done on data. 2. Memory – before a computer can do any productive work such as programming, it has to remember things such as data it needs to produce information. 3. Input and Output Device – data have to come into the computer by first entering them through input devices. Ex. Keyboard. After the computer executes a program to process data and produce information, this information remains in the memory. Part of the program has to show these results to the outside world. Output devices such as monitor screen and printers are used to display the results to the user. 4. Software – computers today come bundled with some software already installed in them. Operating System – performs for the programmer many tasks that used to be very difficult to program Two forms of Memory • Internal Memory (RAM-Random Access Memory) – stores programs and data that are executed and processed by the computer. • Secondary Memory – supplements RAM so those computers are able to permanently save programs and data that are not yet needed for execution and processing. Ex. Floppy disk, hard disk & etc. The following are standard Operating System functions. • Validating user identification every time the user uses the computer • Provides standard functions like editor, compilers and linkers • Manages files of the user by providing functions like Copy, Delete, Append • Retrieves data out of data files • Manages memory for the user by determining where in the memory a program is to be loaded every time it is called to run • Makes communication between the CPU, Memory and input/output devices transparent to the user or the user are unaware of these things while they are at work.
  • 4. By: Froilan G. Cantillo Programming Logic and Design INTRODUCTION OF COMPUTER PROGRAMMING 4 High level languages • Programming languages that are closer to human language than to machine language. They are characterized to use common English words as their instructions. Aside from that, high level languages have the following characteristics: • Requires additional step of compilation or translation so that from high- level, another program that has exactly the same meaning and intended results in low-level or machine language can be generated and loaded into the computer and executed. • A compiled program is usually not as efficient as when the program was originally written in machine language or assembly. This is due to the fact that compilers add a lot of extra overheads in terms of memory and non-optimized logical translations. Each of these programming languages was designed to solve particular kinds of problems. • COBOL – Common Business Oriented Language was designed to solve business problems like accounting. • FORTRAN – Formula Translation is a high level language used for scientific and engineering applications. • Pascal and C – are general-purpose language. They are high-level language but they can be embedded with assembly language code effectively making these languages middle-level languages. C language is responsible in the implementation of major software including operating systems, compilers and software development tools The Simplest computer programs perform three basic operations: • Get the input from the keyboard. • Process the input data. • Display the results on the screen. INPUT DATA PROCESS DATA DISPLAY ALL RESULT
  • 5. By: Froilan G. Cantillo Programming Logic and Design COMPUTER LANGUAGE 5 Programming Language • A programming language is a set of rules that provides a way of telling a computer what operations to perform. • A programming language is a set of rules for communicating an algorithm • It provides a linguistic framework for describing computations • The grammatical rules are called syntax. • Each programming language has a different set of syntax rules. Why are there so many programming languages? • Programming languages have evolved over time as better ways have been developed to design them. o First programming languages were developed in the 1950s. o Since then thousands of languages have been developed. • Different programming languages are designed for different types of programs. Classification of Programming Language Programming Languages - Generations • High level languages o 4th Generation Data query, analysis and reporting o 3rd Generation Imperative • Low level languages o 2nd Generation Assembly o 1st Generation Machine code
  • 6. By: Froilan G. Cantillo Programming Logic and Design COMPUTER LANGUAGE 6 Low-Level Language: • Machine code and Assembly code High-Level Language: • A programming language that allows programs to be written using English keywords and is platform independent Low-Level Language: • Advantages o Achieves a smaller memory footprint (compact). o Achieves better code optimization and therefore code will run faster and more efficiently. o Allows direct manipulation if the registers on the processors, giving high levels of control. o Processors in these systems may be slow and have limited memory so the efficiency of assembly language or machine code is needed. Also useful real time control systems where speed is very important. o Since you are writing at machine level you control the level of the code created. o Can be easily modified. • Disadvantages o More difficult to understand, maintain and debug than high level languages. o More difficult to write without making errors. o Machine dependent making it difficult to port to a different instruction set processor Memory addresses and operations have to be remembered Low Level Languages.
  • 7. By: Froilan G. Cantillo Programming Logic and Design COMPUTER LANGUAGE 7 What are the types of programming languages? • First Generation Languages • Second Generation Languages • Third Generation Languages • Fourth Generation Languages • Fifth Generation Languages First Generation Language • Machine language o Operation code – such as addition or subtraction. o Operands – that identify the data to be processed. o Machine language is machine dependent as it is the only language the computer can understand. o Very efficient code but very difficult to write. Second Generation Languages • Assembly languages o Symbolic operation codes replaced binary operation codes. o Assembly language programs needed to be “assembled” for execution by the computer. Each assembly language instruction is translated into one machine language instruction. o Very efficient code and easier to write. o Does the world need new languages? Third Generation Languages • Closer to English but included simple mathematical notation. o Programs written in source code which must be translated into machine language programs called object code. o The translation of source code to object code is accomplished by a machine language system program called a compiler. • Alternative to compilation is interpretation which is accomplished by a system program called an interpreter. • Common third generation languages o FORTRAN o COBOL o C and C++ o Visual Basic Fourth Generation Languages • A high level language (4GL) that requires fewer instructions to accomplish a task than a third generation language. • Used with databases o Query languages o Report generators o Forms designers o Application generators
  • 8. By: Froilan G. Cantillo Programming Logic and Design COMPUTER LANGUAGE 8 Fifth Generation Languages • Declarative languages • Functional(?): Lisp, Scheme, SML o Also called applicative o Everything is a function • Logic: Prolog o Based on mathematical logic o Rule- or Constraint-based Beyond Fifth Generation Language • Though no clear definition at present, natural language programs generally can be interpreted and executed by the computer with no other action by the user than stating their question. • Limited capabilities at present. The principal paradigm • Imperative Programming (C) • Object-Oriented Programming (C++) • Logic/Declarative Programming (Prolog) • Functional/Applicative Programming (Lisp) Traditional Programming Language • FORTRAN o FORmula TRANslation. o Developed at IBM in the mid-1950s. o Designed for scientific and mathematical applications by scientists and engineers. • COBOL o COmmon Business Oriented Language. o Developed in 1959. ◦ Designed to be common to many different computers. o Typically used for business applications. • BASIC o Beginner’s All-purpose Symbolic Instruction Code. o Developed at Dartmouth College in mid 1960s. o Developed as a simple language for students to write programs with which they could interact through terminals. • C o Developed by Bell Laboratories in the early 1970s. o Provides control and efficiency of assembly language while having third generation language features. o Often used for system programs. ◦ UNIX is written in C.
  • 9. By: Froilan G. Cantillo Programming Logic and Design COMPUTER LANGUAGE 9 Object-Oriented Programming Language • Simula o First object-oriented language o Developed by Ole Johan Dahl in the 1960s. • Smalltalk o First purely object-oriented language. o Developed by Xerox in mid-1970s. o Still in use on some computers. • C++ o It is C language with additional features. o Widely used for developing system and application software. o Graphical user interfaces can be developed easily with visual programming tools. • JAVA o An object-oriented language similar to C++ that eliminates lots of C++’s problematic features. o Allows a web page developer to create programs for applications, called applets that can be used through a browser. o Objective of JAVA developers is that it be machine, platform and operating system independent. Special Programming Language • Scripting Languages o JavaScript and VBScript o Php and ASP o Perl and Python • Command Languages o sh, csh, bash • Text processing Languages o LaTex, PostScript • HTML o HyperText Markup Language. o Used on the Internet and the World Wide Web (WWW). o Web page developer puts brief codes called tags in the page to indicate how the page should be formatted. • XML o Extensible Markup Language. o A language for defining other languages.
  • 10. By: Froilan G. Cantillo Programming Logic and Design BRIEF HISTORY OF PROGRAMMING LANGUAGE 10 • 1842- 1843 (First Computer Program created by Ada Lovelace o Work on the Charles Babbage’s analytical engine. A complete detail a method for calculating Bernoulli numbers with the engine • 1890 Census data on punch cards encoded by Herman Hollerith • 1943-1945 (PLANKALKÜL DEVELOPED FOR THE GERMAN Z3 BY KONRAD ZUSE) o An early high-level programming language to be designed for a computer but was not implemented. • 1949 (SHORT CODE DEVELOP BY JOHN MAUCHLY) o One of the first high-level languages ever developed for an electronic computer. Short code statements are represented by mathematical expressions. • 1952 (MANCHESTER MARK 1 DEVELOPED BY ALICK GLENNIE) o Considered as first compiled high – level programming language. o Automatically convert language into a machine code. • 1957 (FORTRAN CREATED BY JOHN BACKUS) o For numeric and scientific computing (as an alternative to assembly language). o Oldest programming language used today. • 1959 COBOL (COMMON BUSINESS- ORIENTED LANGUAGE) CREATED BY SHORT RANGE COMMITTEE) o High-level. Primarily for business computing. First programming language to be mandated by the US Department of Defense. Primary Uses: Business software (esp. finance and administration systems, but also banks, insurance agencies, governments, military agencies) Used By: Credit cards, ATMs *Fun Fact Action movie The Terminator used samples of Cobol source code for the text shown in the Terminator’s vision display. • 1964 BASIC (BEGINNER’S ALL-PURPOSE SYMBOLIC INSTRUCTION CODE) CREATED BY JOHN GEORGE KENNY AND THOMAS EUGENE KURTZ (SRC) o Designed for simplicity. o Computer games were often written in Basic. (Microsoft’s Altair, Apple II) • 1970 (PASCAL (BLAISE PASCAL) CREATED BY NIKLAUS WIRTH) o For teaching structured programming and data structuring. Commonly used for Windows Application development. • 1972 (C CREATED BY DENNIS RITCHIE OF BELL LABS) o o Currently the world’s most popular programming language.2 Many leading languages are derivatives, including C#, Java, JavaScript, Perl, PHP, and Python. System programming, computer game development.
  • 11. By: Froilan G. Cantillo Programming Logic and Design BRIEF HISTORY OF PROGRAMMING LANGUAGE 11 • 1980 (ADA (AFTER ADA LOVELACE, CREATED BY JEAN ICHBIAH) o Derived from Pascal. o For developing large software systems. o Primary Uses: Dept. of Defense, banking, manufacturing, transportation, commercial aviation • 1983 (C++ (FORMERLY “C WITH CLASSES”) CREATOR BJARNE STROUSTRUP) o An extension of C, with enhancements such as classes, virtual functions, and templates. o Primary Uses: Commercial application development, embedded software, server/client applications, video games o Used by: Adobe, Google Chrome, Mozilla Firefox, Microsoft Internet Explorer • 1983 OBJECTIVE-C (OBJECT-ORIENTED EXTENSION OF “C”) CREATOR: BRAD COX AND TOM LOVE OF STEPSTONE o Expanded on C, adding message-passing functionality based on Smalltalk language. o Used by: Apple’s OS X and iOS operating systems • 1991 PYTHON (FOR BRITISH COMEDY TROUPE MONTY PYTHON) CREATOR: GUIDO VAN ROSSUM OF CWI o Created to support a variety of Programming styles and be fun to use. o Primary Uses: Web application, software development, information security o (Google, Yahoo, Spotify) • 1993 RUBY (THE BIRTHSTONE OF ONE OF THE CREATOR’S COLLABORATOR) CREATOR: YUKIHIRO MATSUMOTO o Designed for productive and enjoyable programming. (Twitter, Hulu, Groupon) Primary Uses: Web application development • 1994 (JAVA CREATOR: JAMES GOSLING OF MICROSYSTEMS) o Made for an interactive TV project. Cross-platform functionality. Second most popular language (behind C).(Android OS/apps) o Primary Uses: Network programming, web application development, software development, Graphical User Interface development • 1994 (JAVA CREATOR: JAMES GOSLING OF MICROSYSTEMS)
  • 12. By: Froilan G. Cantillo Programming Logic and Design BRIEF HISTORY OF PROGRAMMING LANGUAGE 12 • 1995 (PHP (“PERSONAL HOME PAGE”) CREATOR: RASMUS LERDORF) o For building dynamic web pages. Most widely used open-source software by enterprises. o Primary Uses: Building/maintaining dynamic web pages, server- side development o Used by: Facebook, Wikipedia, Digg, WordPress, Joomla • 1995 (PHP (“PERSONAL HOME PAGE”) CREATOR: RASMUS LERDORF) • 1996 (JAVASCRIPT (FINAL CHOICE AFTER “MOCHA” AND “LIVESCRIPT” CREATOR: BRENDAN EICH OF NETSCAPE) o Created to extend web page functionality. o Dynamic web pages’ use for form submission/validation, interactivity, animations, user activity tracking, etc. o Primary Uses: Dynamic web development, PDF documents, web browsers, desktop widgets o Used By: Gmail, Adobe Photoshop, Mozilla Firefox • 1996 (JAVASCRIPT (FINAL CHOICE AFTER “MOCHA” AND “LIVESCRIPT” CREATOR: BRENDAN EICH OF NETSCAPE)
  • 13. By: Froilan G. Cantillo Programming Logic and Design HIERARCHY OF HIGH LEVEL LANGUAGES 13 High Level Languages • High level languages are problem-orientated whereas low level languages are machine-orientated. • Problem-orientated means that the commands and the way the program is structured are based on what the program will have to do rather than the components of the computer it will be used with. • This means that programs of high level languages are portable. These programs can be written on one computer and then executed on another. • There are many types of high level languages, each is written to cope with the demands of specific types of problems. E.g. some are designed for scientific applications, manipulating databases, creating web pages etc. • There are 2 classified groups of high level languages o Imperative o Declarative High Level Programming Languages Imperative Object Oriented Procedural Declarative Logic Database Query Functional
  • 14. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM 14 What is an algorithm? • A set of steps to accomplish a task • An algorithm is a sequence of unambiguous instruction • An algorithm is a well-defined procedure that allows a computer to solved a problem. • An algorithm is a self-contained step-by-step set of operation to be performed to solve a specific problem. How to write an algorithm? • Keep in mind that algorithm is a step-by-step process. • Depending upon programming language, include syntax where necessary. • Include variables and their usage. • If they are any loops, try to give sub number lists. • Try to give go back to step number if loop or condition fails. • Use jump statement to jump from one statement to another. • Try to avoid unwanted raw data in algorithm. • Use break and stop to terminate the process. Characteristics of an Algorithm • Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning. • Input − An algorithm should have 0 or more well-defined inputs. • Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output. • Finiteness − Algorithms must terminate after a finite number of steps. • Feasibility − Should be feasible with the available resources. • Independent − An algorithm should have step-by-step directions, which should be independent of any programming code. Two forms of Algorithm: • Pseudocode • Flowchart
  • 15. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM: PSEUDOCODE 15 Pseudocode Pseudocode essentially is English with some defined rules of structure and some keywords that make it appear a bit like program code. Some guidelines for writing pseudocode are as follows. Pseudocode Guidelines • The keywords used for pseudocode in this document are: 1. for start and finish BEGIN MAINPROGRAM, END MAINPROGRAM 2. for initialization INITIALISATION, END INITIALISATION 3. for subprogram BEGIN SUBPROGRAM. END SUBPROGRAM 4. for selection IF. THEN, ELSE, ENDIF 5. for multi-way selection CASEWHERE. OTHERWISE. ENDCASE 6. for pre-test repetition WHILE. ENDWHILE 7. for post-test repetition REPEAT. UNTIL • Keywords are written in CAPITALS. • Structural elements come in pairs, o for every BEGIN there is an END o for every IF there is an ENDIF. etc. • Indenting is used to show structure in the algorithm. • The names of subprograms are underlined. o This means that when refining the solution to a problem. a word in an algorithm can be underlined and a subprogram developed. This feature enables the use of the 'top-down' development concept. where details for a particular process need only be considered within the relevant sub-routine.
  • 16. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM: FLOW CHARTS 16 Flow Charts • A drawing that uses symbols interconnected with lines to represent the flow of information • A process flow diagram that illustrates the successive steps in a process, procedure, system or model. • A pictorial representation showing/describing all of the steps of a process being studied or even used to plan stages of a project. Flow charts tend to provide people with a common language or reference point when dealing with a project or process. Purpose of Flow Charts A Flowchart is used for: 1. Defining and analyzing processes 2. Building a step-by-step picture of the process for analysis, discussion, or communication purposes 3. Defining, standardizing, or finding areas for improvement in a process By visualizing the process, a flowchart can quickly help identify bottlenecks or inefficiencies where the process can be streamlined or improved. Basic flowcharting shapes and symbols Flowcharts use special shapes to represent different types of actions or steps in a process and Lines and arrows show the sequence of the steps, and the relationships among them. Start/End – The terminator symbol marks the starting or ending point the system. It usually contains the word "Start" or "End." Action or Process – A box can represent a single step ("add two cups of flour), or and entire sub-process ("make bread") within a larger process. Decision – A decision or branching point. Lines representing different decisions emerge from different points of the diamond.
  • 17. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM: FLOW CHARTS 17 Connector – Indicates that the flow continues where a matching symbol containing the same letter) has been placed. Flow Line – Lines indicate the sequence of steps and the direction of flow. Input/ Output – Represents material or information entering or leaving the system, such as customer order (input) or a product Example of Flowchart
  • 18. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM: FLOW CHARTS 18 Common Types of Flowcharts There are four flowchart types that are particularly versatile. These four common diagrams are great for describing business, manufacturing, or administrative processes, seeing how an organization functions, or how different departments work together. 1. The Process Flowchart Illustrate How a Process Works or Plan a Project with a Process Flowchart A process flowchart or process flow diagram is probably the most versatile of the four commonly used flowchart types because it can be applied to virtually anything. • Map out roles and responsibilities within an organization to gain clarity. • Draw up a proposal for a new process or project to understand its scope and steps. 2. The Workflow Chart Understand How Data and Documents Flow Within Your Organization A workflow chart shows the way a business or process functions. This type of workflow diagram can be used to: • Train new employees • Discover potential problem areas • Clarify business operations by showing a high-level overview 3. The Swimlane Flowchart Describe How Separate Departments, Processes or Employees Interact The swimlane flowchart comes in handy when you need to show multiple flows of information side by side. Swimlane diagrams might sound really similar to a workflow diagram, but the key here is that it allows you to create different categories where activity takes place. A swimlane flowchart or diagram is great for documenting a whole process that interacts with different segments of an organization or requires collaboration among different teams. 4. The Data Flowchart See Where Data Flows In and Out of an Information System with a Data Flow Diagram A data flowchart or data flow diagram shows the way data is processed. It comes in handy when you want to design or analyze a system. Although most often used for software development and design, it can be used to analyze any type of information flow, like how information moves through a business.
  • 19. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM: FLOW CHARTS 19 Steps for creating a flowchart are: 1. Familiarize the participants with the flowchart symbols 2. Brainstorm major process tasks. Ask questions such as "What really happens next in the process? ", "Does a decision need to be made before the next step? ", or What approvals are required before moving on to the next task?" 3. 3Draw the process flowchart using the symbols on a flip chart or overhead transparency. Every process will have a start and an end (shown by elongated circles). All processes will have tasks and most will have decision points (shown by a diamond). 4. Analyze the flowchart for such items as: • Time-per-event (reducing cycle time) 0 Process repeats (preventing rework) • Duplication of effort (identifying and eliminating duplicated tasks) • Unnecessary tasks (eliminating tasks that are in the process for no apparent reason) • Value-added versus non-value-added tasks CONSTRUCTION/INTERPRETATION tip for a flow chart. • Define the boundaries of the process clearly. • Use the simplest symbols possible. • Make sure every feedback loop has an escape. • There is usually only one output arrow out of a process box. Otherwise, it may require a decision diamond. • Analyze flow chart of actual process. • Analyze flow chart of best process. • Compare both charts, looking for areas where they are different. Most of the time, the stages where differences occur is considered to be the problem area or process. • Take appropriate in-house steps to correct the differences between the two separate flows.
  • 20. By: Froilan G. Cantillo Programming Logic and Design ALGORITHM: FLOW CHARTS 20 Tips for Effective Flowcharts 1. Label each flowchart with a title identifying the process that it illustrates. (For example: Entry Process"). 2. Clearly indicate the starting and ending points of the process, using the standard terminator symbols. 3. Keep the direction of flow consistent. Avoid confusion by keeping your flow lines moving from top to bottom and left to right. Don't reverse the direction in the chart unless the flow reverses itself in reality. 4. Break the steps down to a consistent level of detail. Don't include trivial sub-steps of one task while treating another equivalent task as a whole. If one step or task needs to be analyzed in detail, make a separate chart illustrating that sub-process. • You can hyperlink the shape representing a sub-process that, illustrates it, allowing users to "drill down" for more detail.) 5. Avoid crossing flow lines. In a well-designed chart, flow lines will not cross each other. By rearranging a chart, you can usually get rid of crossed lines. If two lines must cross, use a "bridge" (also known as a "line hop") to show that the lines do not intersect. 6. Make sure there are at least two no outcomes from every decision diamond. 7. Label your flowchart components. Use active verbs to label activity steps and questions to label decisions. Clearly label the form a decision diamond in terms that answer the question. Flowchart and Pseudocode
  • 21. By: Froilan G. Cantillo Programming Logic and Design DATA TYPES 21 Data Types • A data type defines a set of values and a set of operation on those values. A C++ program may need to required different type of data. Each type required different type of memory. • It indicates the type of data that can be store in a variable • There are three basic data type. o Character o Integer o Float Character data type • This data type is used to store character values. • Characters may include letters, digits and punctuation character. It take one byte in memory i.e. ‘a’ and ‘@’ etc. • Represented by the “char” data type. • The “short” data type is the same size as “char” usually one byte. • The character variable can store only one character • The Character range is “-128 to 127” We can declare it as below. Char a= ‘A’ Char f= ‘B’ Char z= ‘D’ etc Integer data type: • A numeric value with no fraction is called integer data. It include both positive and negative values. • Represented by “int” • Int range –32,768 to 32,767 • Some example of integer value are 56 and -12 • Int size is ‘2’ bytes • Long int size ‘4’ bytes We can declare it as below. Int a=20; Int b=40; Int c=30;
  • 22. By: Froilan G. Cantillo Programming Logic and Design DATA TYPES 22 Type of Integer data type Int data type • To store integer values and takes two byte in memory. i.e. int num; Long int data type • To store large integer value. It has greater range and takes ‘4’ bytes in memory. i.e. long int num; Float data type: • A numeric value with fraction is called real data type / float data type. It include both • Positive and negative values. i.e. 12.4 and -34.3 • This data type are represented by “float”. • Float number are declared as Float a= “40.00” Float b= “23.04” Float c= “10.3” etc. Type of float • Float data type o This data type is used to store real values and o Takes ‘4’ bytes in memory. i.e. Float num; • Double data type o It has great range as compared to float and takes ‘8’ byte in memory. i.e. Double num;
  • 23. By: Froilan G. Cantillo Programming Logic and Design DATA TYPES 23 Variable • A quantity whose values may change during the execution of the program is called variable. • It may be a numeric or non-numeric quantity • It represented by an identifier called variable name • A variable represents a memory location in the computer memory. Data is store into the memory location. The name of memory location or variable name remains fixed during the execution of the program but the data store in that location may change from time to time Variable Declaration • A variable is case sensitive, that is, uppercase variables are treated differently • Variable “SUM” is different from variable “sum” • Variable “NetPay” is different from variable “NETpay” Rules for variable Declaration • Variable may include letter, number and underscore (_) • The first latter of the variable must be character or underscore. • Blank spaces special symbols, commas are not used • A variable can be ‘31’ character long for many compilers • Key word are not used as variable name. Variable Declaration • The process of specifying the name and its data type is called variable declaration • All variables that are used in a program are declared using variable declaration statement. • When a variable is declared a certain number of bytes in the memory are allocated to the variable name. Variable Initialization • The process of assigning a value to a variable at the time of declaration is known as variable initialization. • The equal (=) is used to initialize a variable. • Variable name is given on the left side and value is given on the right side of equal sign.
  • 24. By: Froilan G. Cantillo Programming Logic and Design arduino.cc ARDUINO 24 Introduction Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. What is Arduino? • Arduino is an open-source electronics platform based on easy-to-use hardware and software. • Arduino boards are able to read inputs and turn it into an output. • You can tell your board what to do by sending a set of instructions to the microcontroller on the board. • Arduino was born at the Ivrea Interaction Design Institute • Easy tool for fast prototyping • Aimed at students without a background in electronics and programming. Why Arduino? • Arduino has been used in thousands of different projects and applications. • The Arduino software is easy-to-use for beginners, yet flexible enough for advanced users. • It runs on Mac, Windows, and Linux. Teachers and students use it to build low-cost scientific instruments or to get started with programming and robotics. • Arduino is a key tool to learn new things. • Anyone can start tinkering just following the step-by-step instructions of a kit, or sharing ideas online with other members of the Arduino community. Inexpensive – Arduino boards are relatively inexpensive compared to other microcontroller platforms. Cross-platform – The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux operating systems. Most microcontroller systems are limited to Windows. Simple, clear programming environment – The Arduino Software (IDE) is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well. Open source and extensible software – The Arduino software is published as open source tools, available for extension by experienced programmers. Open source and extensible hardware – The plans of the Arduino boards are published under a Creative Commons license, so experienced circuit designers can make their own version of the module, extending it and improving it.
  • 25. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO 25
  • 26. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO: UNO 26 Arduino Uno Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM, 32KB flash storage) Features: 14 digital I/O pins, 6 analog input pins, removable microcontroller Form Factor: 2.7” x 2.1” rectangle The Arduino Uno is the most “standard” Arduino board currently on the market, and is probably the best choice for beginners just getting started with the platform. The board is compatible with more shields (add-on boards) than other models. The Uno’s main limitation is the ATmega328 chip, which doesn’t have a lot of SRAM or flash memory. That limit’s the kinds of programs you can load on the chip – if your project involves a display or otherwise needs to store and use any form of images or audio data, 2KB of memory probably isn’t going to be enough.
  • 27. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO : MEGA 27 Arduino Mega Processor: ATmega2560 (8-bit CPU, 16MHz clock speed, 8KB SRAM, 256KB flash storage) Features: 54 digital I/O pins (15 PWM), 16 analog input pins, 4 UARTs, 16 MHz crystal oscillator Form Factor: 101.52mm x 53.3mm rectangle The Mega is a microcontroller board based on the ATmega2560. The Mega is compatible with most shields designed for the Arduino Duemilanove or Diecimila. It is intended for comparatively bigger projects requiring a large number of input and output pins.
  • 28. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO : NANO 28 Arduino Nano Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM, 32KB flash storage) Features: 22 digital I/O pins, 8 analog input pins Form Factor: 18mm x 45mm rectangle The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega.328 (Arduino Nano 3.x). It has more or less the same functionality of the Arduino Duemilanove, but in a different package. It lacks only a DC power jack, and works with a mini-B USB cable instead of a standard one.
  • 29. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO: MINI 29 Arduino Mini Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM, 32KB flash storage) Features: 14 digital I/O pins, 8 analog input pins, 16 MHz crystal oscillator Form Factor: 30mm x 18mm rectangle The Arduino Mini is a small microcontroller board originally based on the ATmega168, but now supplied with the 328 (datasheet), intended for use on breadboards and when space is at a premium. The new Mini (revision 05) has a new package for the ATmega, which enable all components to be on the top of the board. It also has an onboard reset button.
  • 30. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO: LEONARDO 30 Arduino Leonardo Processor: ATmega32u4 (8-bit CPU, 16MHz clock speed, 2KB SRAM, 32KB flash storage) Features: 20 digital I/O pins (7 PWM), 12 of which can be used as analog inputs, native USB support Form Factor: 68.6mm x 53.3mm rectangle The Leonardo is, essentially, a slight upgrade to the Uno. It looks a lot like the Uno, but it features a soldered-on ATmega32u4 microcontroller with a tiny bit more memory. The main advantage of the ATmega32u4 isn’t the extra SRAM, though, it’s the chip’s built-in USB compatibility. This allows the Leonardo to interface with a PC, which sees it as a generic mouse or keyboard. It also features a few extra analog input pins.
  • 31. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO: DUE 31 Arduino Due Processor: Atmel SAM3X8E ARM Cortex-M3 (32-bit CPU, 84MHz clock speed, 96KB SRAM, 512KB flash storage) Features: 54 digital I/O pins (12 PWM), 12 analog input pins, 2 analog output pins, native USB port Form Factor: 101.52mm x 53.3mm rectangle One of the newest Arduino boards, the Due is the heavy-hitter of the family, packing a 32-bit ARM processor that handily outclasses any of the processors found in other Arduino boards. The Due is primarily for more complicated projects that can make sure of its muscular processor, or that need more I/O pins than are found on the smaller Arduino boards. That said, the Due is substantially bigger and more expensive than the Uno or Leonardo, so consider whether you really need the extra power before making a purchase. One drawback to the Due is that it operates at 3.3 volts, which is different than the 5 volts that most other Arduino boards operate at. That limits the add-on hardware that’s compatible with the Arduino Due – if an add-on board tries to send a 5 volt signal to the Due’s I/O pins, it could damage the microcontroller.
  • 32. By: Froilan G. Cantillo Programming Logic and Design arduino.cc TYPES OF ARDUINO LILYPAD 32 Arduino Lilypad Processor: ATmega328 (8-bit CPU, 16MHz clock speed, 2KB SRAM, 32KB flash storage) Features: 14 digital I/O pins, 6 analog input pins Form Factor: 2” diameter circle The Lilypad is an Arduino board specifically designed for wearable devices. Its circular shape and standoff-less I/O pins are designed to make it easy to sew the Lilypad into fabric-based projects. The hardware on a standard LilyPad board is basically the same as on and Arduino Uno. There are a number of other LilyPad options available as well, including the LilyPad Arduino USB, which feature’s the Leonardo’s ATmega32u4 chip, the Lilypad Arduino Simple, which has fewer I/O connections than the basic model, and the LilyPad Arduino SimpleSnap, which can be snapped into and out of projects, so they can be safely washed.
  • 33. By: Froilan G. Cantillo Programming Logic and Design arduino.cc PARTS OF ARDUINO UNO 33 1 – Power USB Arduino board can be powered by using the USB cable from your computer. All you need to do is connect the USB cable to the USB connection (1). 2 – Power (Barrel Jack) Arduino boards can be powered directly from the AC mains power supply by connecting it to the Barrel Jack (2). 3 – Voltage Regulator The function of the voltage regulator is to control the voltage given to the Arduino board and stabilize the DC voltages used by the processor and other elements. 4 – Crystal Oscillator The crystal oscillator helps Arduino in dealing with time issues. How does Arduino calculate time? The answer is, by using the crystal oscillator. The number printed on top of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16 MHz. 5,17 – Arduino Reset You can reset your Arduino board, i.e., start your program from the beginning. You can reset the UNO board in two ways. First, by using the reset button (17) on the board. Second, you can connect an external reset button to the Arduino pin labelled RESET (5).
  • 34. By: Froilan G. Cantillo Programming Logic and Design arduino.cc PARTS OF ARDUINO UNO 34 6,7,8,9 – Pins (3.3, 5, GND, Vin) • 3.3V (6) − Supply 3.3 output volt • 5V (7) − Supply 5 output volt • Most of the components used with Arduino board works fine with 3.3 volt and 5 volt. • GND (8)(Ground) − There are several GND pins on the Arduino, any of which can be used to ground your circuit. • Vin (9) − This pin also can be used to power the Arduino board from an external power source, like AC mains power supply. 10 – Analog pins The Arduino UNO board has six analog input pins A0 through A5. These pins can read the signal from an analog sensor like the humidity sensor or temperature sensor and convert it into a digital value that can be read by the microprocessor. 11 – Main Microcontroller Each Arduino board has its own microcontroller (11). You can assume it as the brain of your board. The main IC (integrated circuit) on the Arduino is slightly different from board to board. The microcontrollers are usually of the ATMEL Company. You must know what IC your board has before loading up a new program from the Arduino IDE. This information is available on the top of the IC. For more details about the IC construction and functions, you can refer to the data sheet.
  • 35. By: Froilan G. Cantillo Programming Logic and Design arduino.cc PARTS OF ARDUINO UNO 35 12 – ICSP pin Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial Peripheral Interface), which could be considered as an "expansion" of the output. Actually, you are slaving the output device to the master of the SPI bus. 13 – Power LED indicator This LED should light up when you plug your Arduino into a power source to indicate that your board is powered up correctly. If this light does not turn on, then there is something wrong with the connection. 14 – TX and RX LEDs On your board, you will find two labels: TX (transmit) and RX (receive). They appear in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins responsible for serial communication. Second, the TX and RX led (13). The TX led flashes with different speed while sending the serial data. The speed of flashing depends on the baud rate used by the board. RX flashes during the receiving process.
  • 36. By: Froilan G. Cantillo Programming Logic and Design arduino.cc PARTS OF ARDUINO UNO 36 15 – Digital I/O The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse Width Modulation) output. These pins can be configured to work as input digital pins to read logic values (0 or 1) or as digital output pins to drive different modules like LEDs, relays, etc. The pins labeled “~” can be used to generate PWM. 16 – AREF AREF stands for Analog Reference. It is sometimes, used to set an external reference voltage (between 0 and 5 Volts) as the upper limit for the analog input pins.
  • 37. By: Froilan G. Cantillo Programming Logic and Design arduino.cc ARDUINO IDE 37 Arduino Software You can download the Arduino IDE (The program used to write code and uploading it to Arduino boards) from https://www.arduino.cc/en/software Connect your Arduino Uno to your PC via USB Cable Select your board • Tools → Board: “Arduino/Ginuino Uno” → Arduino/Ginuino Uno Select your serial port • Tools → Port Compile: • Compile the sketch after writing the code • Check your codes for error Upload: • Upload the program to the configured Arduino board New Open Save Serial Monitor Name of Sketch Verify: Compile Sketch Upload: Upload the program to the board Code Area Messages / Error
  • 38. By: Froilan G. Cantillo Programming Logic and Design arduino.cc STRUCTURE: SKETCH 38 The basic code structure of Arduino programming is simple and is composed of two parts: 1. Setup 2. Loop The code you write for your Arduino are known as sketches. They are written in C++. Every sketch needs two void type functions, setup() and loop(). A void type function doesn’t return any value. The setup() method is ran once, just after the Arduino is powered up, and the loop() method is ran continuously afterwards. The setup() is where you want to do any initialization steps, and in loop() you want to run the code you want to run over and over again.
  • 39. By: Froilan G. Cantillo Programming Logic and Design arduino.cc if Statement ‘if’ statements test whether a certain condition has been reached, such as whether a number has reaches a certain value, and if true, executes the statements in the brackets. The code in the brackets is skipped if the statement is false. The syntax for if statement is: void loop(){ if(somevariable <testcondition> value){ doSomething; } } The above condition test compares somevariable with a value. If this condition is satisfied, then the code inside the parenthesis (dosomething) is executed. STRUCTURE: CONTROL STRUCTURE 39 If…else The ‘if…else’ statements allow either/or statements to be made. These statements can be used when more than one courses of action are possible, as determined by the variable or value being tested. The syntax for ‘if…else’ implementation is: void loop(){ if(inputPin == HIGH){ doThing1; }else{ doThing2; } }
  • 40. By: Froilan G. Cantillo Programming Logic and Design arduino.cc STRUCTURE: CONTROL STRUCTURE 40 If…else if ladder If more than two courses of action are possible, then the ‘if…else if’ ladder is to be used, which allows the choice and execution of one statement from an infinite number of possibilities. The syntax is as follows: void loop(){ if(inputPin <testcondition> value1){ doThing1; }else if(inputPin <testcondition> value2){ doThing2; }else if(inputPin <testcondition> value3){ doThing3; }else{ doThing4; } } for Statement The ‘for’ statement is used to repeat a statement of a block of statements a specified number of times. The arguments for the ‘for’ loop consists of: 1. Initialization. This initializes a variable with a specified initial value. 2. Test condition. This condition is tested for every loop and the ‘for’ statement stops looping when this condition does not hold true. 3. Increment/decrement expression. This expression operates on the initialized variable. The syntax for the ‘for’ loop is as follows: void loop(){ for(initialization; condition; increment/decrement expression){ doSomething; } }
  • 41. By: Froilan G. Cantillo Programming Logic and Design arduino.cc STRUCTURE: CONTROL STRUCTURE 41 while Loop The ‘while’ loop will loop continuously and infinitely, until the expression inside the brackets become false. If the tested variable of value is not changed, the loop will go on for infinity. void loop(){ while(variable <test condition> value){ doSomething; } } do…while Loop The ‘do…while’ class works in a similar manner to the ‘while’ class, the only difference being, that, in the ‘do…while’ class the condition is tested at the bottom of the loop, making sure the loops is carried out at least once. void loop(){ do{ doSomething; }while(variable <test condition> value) }
  • 42. By: Froilan G. Cantillo Programming Logic and Design arduino.cc CONSTANT: HIGH/LOW 42 HIGH/LOW These are constraints used to signify 0V or 5V (logic 0 or 1) when writing or reading from digital pins. In the following example, if the pin value on pin 11 is HIGH, the pin value on pin 12 is set as HIGH. void setup(){ pinMode(12, OUTPUT); pinMode(11, INPUT); } void loop(){ if(digitalRead(11) == HIGH){ digitalWrite(12, HIGH); } }
  • 43. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: DIGITAL INPUT/OUTPUT 43 pinMode This command is used to set pins as input or output in the Setup(). Arduino digital pins are set to input by default, hence there is no need to specifically declare them as inputs using pinMode(). Pins configured as inputs are said to be in a high impedance state. The syntax for declaring pins using pinMode() is as follows: void setup(){ pinMode(11, INPUT); //Sets pin 11 as input pinMode(12, OUTPUT); //Sets pin 12 as output } void loop(){ } For convenience there are 20k ohm pull up resistors built into the ATmega chip which can be accessed through software in the following manner: void setup(){ pinMode(11, INPUT); //Sets pin 11 as input digitalWrite(11, HIGH); //Turns on 20k-ohms //pullup resistor } void loop(){ } Pins set as OUTPUT are said to be in a low resistance state and can supply 40mA of current to connected circuits or components.
  • 44. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: DIGITAL INPUT/OUTPUT 44 digitalRead This function is used to read the digital value of a pin. The result is either HIGH or LOW. The syntax is as follows: void setup(){ pinMode(11, INPUT); //Sets pin 11 as input } void loop(){ int value = digitalRead(11); //Sets variable value //equal to the input pin } digitalWrite Sets the pins on or off, by giving them either HIGH or LOW output. The function takes two parameters, the pin number and either HIGH or LOW, as follows: void setup(){ pinMode(12, OUTPUT); //Sets pin 12 as output } void loop(){ digitalWrite(12, HIGH); //Sets value of pin 12 as HIGH }
  • 45. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: ANALOG INPUT/OUTPUT 45 analogRead This function reads the value from a specified analogue pin and returns a value between 0-1023. It only works on the six analogue pins from 0-5. The syntax is as follows: void setup(){ pinMode(0, INPUT); //Sets pin 0 as input } void loop(){ int value = analogRead(0); //Reads the analogue value //between 0-1023) of the //analog pin 0 } analogWrite This function is used to give an analog output. Analog outputs can only be given to pins 3, 5, 6, 9, 10 and 11 on the Uno. Values between 0-255 can be given to the analog pins. The syntax is as follows: void setup(){ pinMode(3, OUTPUT); //Sets pin 3 as output } void loop(){ analogWrite(3, value); //Sets the value of analog pin //3 equal to value (must be //from 0-255) }
  • 46. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: TIME 46 millis() Acts like a clock and returns the number of milliseconds that have passed since the Arduino board began running the current program as an unsigned long int. The clock resets to zero after about 9 hours: void loop(){ int timeelapsed = millis(); //Sets the variable //timelapsed to the number //of milliseconds passed //since program execution } micros() Similar to millis(), it acts like a clock and returns the number of microseconds that have passed since Arduino board began running the current program as an unsigned long int. This number will overflow and become zero again after approximately 70 minutes: Pins set as OUTPUT are said to be in a low resistance state and can supply 40mA of current to connected circuits or components. unsigned long time; void setup()( Serial.begin(9600); } void loop() Serial.print(“Time: "); time = micros(); //prints time since program started Serial.println(time); //wait a second so as not to //send massive amount of data delay(1000); }
  • 47. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: TIME 47 delay(ms) Pauses the program for the specified amount of time. The arguments take time duration in milliseconds: void loop()( digitalWrite(11, HIGH); delay(1000); //Pauses the program for 1000 //millisecond or 1 second } delayMicroseconds(us) Here, ‘us’ is the time in microseconds. Similar to delay(ms), this function pauses the program for the specified amount of time. The arguments take time duration in microseconds as an unsigned int: int outPin = 8; //digital pin 8 void setup(){ pinMode(outPin, OUTPUT); //Sets the digital pin as //output } void loop(){ digitalWrite(outPin, HIGH); //Sets the pin on delayMicroseconds(100); //Pauses for 100 //microseconds digitalWrite(outPin, LOW); //Sets the pin off delayMicroseconds(100); //Pauses for 100 //microseconds }
  • 48. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: MATH 48 min(x,y) Returns the smaller of the two values passed into the function as arguments. void loop(){ int x,y; int smaller_num = min(x,y); //Sets smaller_num equal //to x or y depending upon //whichever is smaller } max(x,y) Returns the larger of the two values passed into the function as arguments. void loop(){ int x,y; int larger_num = max(x,y); //Sets larger_num equal to //x or y depending upon //whichever is larger }
  • 49. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: RANDOM NUMBERS 49 randomSeed(seed) Sets a value as a starting point before the random() function. The seed can be any variable, input, constraints or other functions. Must be used before the random function. void loop(){ randomSeed(analogRead(3)); //Uses the analog value at //pin 3 to set a starting //point for the random //function } random(min,max) This function helps in generating pseudo-random values for the given range in the arguments. The function randomSeed(seed) must be used before using this function. void loop(){ int value_1; int value_2; rendomSeed(analogRead(3)); value_l = random(100); //Sets value_l equal to any //random number between 0 and //100 value_2 = random(50,100): //Sets value_2 equal to any //random number between SO //and 100 }
  • 50. By: Froilan G. Cantillo Programming Logic and Design arduino.cc FUNCTIONS: COMMUNICATION 50 Serial.begin() This function opens up the USB port for serial communication and also sets the baud rate. Typical baud rate for serial communication with computer is 9600bps. void setup(){ Serial.begin(9600); //Opens the serial port and sets //the band rate at 9600bps } Serial.println() Prints the value passed into the brackets on to the Serial Monitor. void loop(){ int value = 100; Serial.println(value); //Prints value on to the Serial //Monitor followed by a return //carry and line feed } Click the encircled link to bring up the Serial Monitor.
  • 51. By: Froilan G. Cantillo Programming Logic and Design arduino.cc REFERENCE 51 https://www.arduino.cc/ https://en.wikipedia.org/wiki/Arduino https://www.slideshare.net/