Professional Documents
Culture Documents
Arduino Langauge
Machine Language
(Binary Code)
Assembly
(Readable Code)
C / C++
(Readable Code)
C++
Libs
C++
Libs
C++
Libs Arduino
2
Arduino Langauge
Arduino
C++
Libs
C++
Libs
C++
Libs
Machine Language
(Binary Code)
Assembly
(Readable Code)
C / C++
(Readable Code)
3
14
15
16
Arduino IDE
19
Type Stuff Here
Compiler Output
Arduino IDE
20
Type Stuff Here
Compiler Output
Serial Monitor
Arduino IDE
21
Type Stuff Here
Compiler Output
Serial MonitorVerify & Upload
Arduino IDE
22
Type Stuff Here
Compiler Output
Serial MonitorVerify & Upload
Board & Serial Port
Blink Exercise
Load the Blink Example and
program it to your board
Change the values of delay()
to see how it affects the
behavior
Check the correct board and serial port are selected in the tools menu!
Hello World
Serial Example
24
Serial objects
25
Serial objects
Enables Serial
BaudRate
26
Serial objects
Variables
Strings
Control Characters
Print
and Println
27
Serial objects
28
Variables
Strings
Control Characters
Print
and Println
NOTE: Strings and Variables Can t be used on the same line
Variables
30
31
Variable Types
Bits Unsigned Range Signed Range
byte 8
8
16
32
32
32
0 to 255
0 to 255
A .. b .. X
0 to 65535
0 to 4,294,967,295
3.4028235E+38
n/a
N/A
N/A
-32,767 to 32,766
-2,147,483,648 to
2,147,483,647
n/a
n/a
char
int
long
float
double
32
Variable Scope
34
Variable Scope
Global
35
Variable Scope
Global
Local to loop()
36
Variable Don t!
37
Variable Don t!
38
Variable Don t!
39
arrays
analogReadings[]
0 1 2 3 4 5
40
arrays
analogReadings[]
0 1 2 3 4 5
41
Size
Elements
arrays
analogReadings[]
0 1 2 3 4 5
42
Size
Elements
arrays are
0-index based.
So last element
is always
1 less
than the size!
Pin Functions
43
pinMode()
Analog(A0..A5)
Digital(0..13)
INPUT Digital Input,
Pull-Up Off
Digital Input,
Pull-Up On
Digital Output
Digital Input,
Pull-Up Off
Digital Input,
Pull-Up On
Digital Output
INPUT_PULLUP
OUTPUT
Analog Pins can be used as Digital Pins
pinMode(INPUT, Ax) isn t necessary for analogRead()
45
Pull-Up Resistor
INPUTs almost always need a Pull-Up or Pull-Down
pinMode(INPUT_PULLUP) Turns on the Internal Pull-Up Resistor
http://www.baldengineer.com/tutorials/arduino-pull-ups/
I/O Exercise
Fix
the random
Analog
Signal
Convert Digital
Value
10-bits, stored as 8-bits
Values 0 to 1023
Voltage
0v to 5v
5 volts
1023 Steps
= 4.887mV per Step
Calling analogRead() on an Analog Pin,
automatically converts to Input
Analog
Signal
Convert Digital
Value
10-bits, stored as 8-bits
Values 0 to 1023
Voltage
0v to 5v
5 volts
1023 Steps
= 4.887mV per Step
Calling analogRead() on an Analog Pin,
automatically converts to Input
analogWrite()
Actual AnalogPulse Width Modulation (PWM)
analogWrite() isn t Analog (Except on the Due)
Uno Pins: 3, 5, 6, 9, 10, 11
Analog Exercise
Analog Exercise
functions()
52
Functions
Getting Data Back
Functions
Getting Data Back
Tip: The Arduino IDE, doesn t require
prototyping
Functions
Getting Data Back
Return Type
Arguments
Return
Function Name
Functions
Returning Nothing
Return Type
If the function doesn t return anything, declare it as void
56
Function Exercise
Control Structures
58
if-statements
59
if-statements
60
if-statements
61
if-statements
62
control operators
== Equal to
Greater than>
>= (or equal)
Less Than<
<= (or equal)
Not Equal to!=
|| OR
AND
Bitwise OR
Bitwise AND
&&
|
&
63
#1 if-statement mistake
64
#1 if-statement mistake
= != ==
65
66
for() loop
67
for() loop
Control Variable
68
for() loop
Control Variable
Condition
69
for() loop
Control Variable
Condition
Increment
70
while() loop
72
while() loop
Condition
73
while() loop
Condition
Loop conditions are same as
74
if conditions
More information?
Visit
baldengineer.com
76