Documente Academic
Documente Profesional
Documente Cultură
Foundations
Topics
1. Introduction
2. Getting Started
3. Sketch Fundamentals
Introduction
What is Arduino?
Inexpensive
Cross-platform
Simple, clear programming environment
Open-source and extensible software
Open-source and extensible hardware
/ 34
Arduino Specifications
Microcontroller ATmega1681
Operating Voltage 5V
Input Voltage (recommended) 7-12 V
Input Voltage (limits) 6-20 V
Digital I/O Pins 14 (of which 6 provide PWM
output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 16 KB (of which 2 KB used by
bootloader)
Integrated Development Environment
The Arduino development environment contains a text
editor for writing code, a message area, a text console,
a toolbar with buttons for common functions, and a
series of menus. It connects to the Arduino hardware
to upload programs and communicate with them.
It can be downloaded at
https://www.arduino.cc/en/Main/Donate
Integrated Development Environment
A few seconds after the upload finishes, you should see the
pin 13 (Lit) LED on the board start to blink (in orange). If it
does, congratulations! You've gotten Arduino up-and-
running
10 16 / 34
Sketch Fundamentals
2010 17 / 34
What is a Sketch?
Definition
Sketch
It is the unit of code that is uploaded to and run on an
Arduino board.
Example
Blink
The sketch we uploaded earlier
Comments
Comments are ignored by the Arduino when it runs the
sketch.
It is there for people reading the code: to explain what
the program does, how it works, or why it's written the
way it is.
For multi-line comment use /* and */.
For single-line comment use //.
Comment Example
/ 34
Variables
Definition
Variable
Place for storing a piece of data
Variable has a name, a value, and a type.
Variable Example
int pin = 13;
Variable Example
Variable Example
In the statement:
pinmode(pin, OUTPUT);
It would be equivalent to the following statement:
pinmode(13, OUTPUT);
Arithmetic Expressions
int counter; /*variable names should always start with a letter*/
Definitions
AND
Symbolized by & (&& if conditional)
Returns True only if all inputs are True, otherwise False.
OR
Symbolized by | (|| if conditional)
Returns True if one or more inputs are True, otherwise False.
Boolean Logic
1010 & 1100
1010 | 1100
Definition
Function
Also known as procedure or subroutine.
A named piece of code that can be used from elsewhere in a sketch.
Definitions
setup() A function that is called once, when the sketch starts.
Setting pin modes or initializing libraries are placed here.
loop() A function that is called over and over and is the
heart of most sketches.
2010 28 / 34
Control Structures
Definition
If-Else Statement
Most basic of all programming control structures.
It allows you to make something happen or not depending on
whether a given condition is true or not.
Syntax
if (some Condition) {
/ do stuff if the condition is true } else {
Example
int test = 0;
if (test == 1) {
printf(“Success”);
} else
{ printf(“Fail”);
Definition
While Loop
Continue program until a given condition is true
Syntax
while(some condition) {
/ do stuff until condition becomes false
}
Definition
For Loop
Distinguished by a loop counter
Syntax
for (start; condition; operation) {
/ do stuff until condition becomes false
}
While Loop
count = 0;
while (count <= 2) {
printf(“Hello”);
count++
}
For Loop
int count;
for (count = 0; count <= 15; count++) {
printf(“Hello”);
}