Lenguaje Usado en Arduino
-
Upload
pedro-espinoza-fernandez -
Category
Documents
-
view
230 -
download
0
Transcript of Lenguaje Usado en Arduino
-
7/23/2019 Lenguaje Usado en Arduino
1/52
Arduino: Lenguaje de
implementacin
Lic. Jorge Guerra Guerra
-
7/23/2019 Lenguaje Usado en Arduino
2/52
The Arduino Environment
-
7/23/2019 Lenguaje Usado en Arduino
3/52
Board Type
-
7/23/2019 Lenguaje Usado en Arduino
4/52
Serial Port !"# Port
-
7/23/2019 Lenguaje Usado en Arduino
5/52
-
7/23/2019 Lenguaje Usado en Arduino
6/52
Part$ o% the S&etch
-
7/23/2019 Lenguaje Usado en Arduino
7/52
!omment$
!omment$ can 'e any(here
-
7/23/2019 Lenguaje Usado en Arduino
8/52
!omment$
!omment$ can 'e any(here
!omment$ created (ith or) and )
-
7/23/2019 Lenguaje Usado en Arduino
9/52
!omment$
!omment$ can 'e any(here
!omment$ created (ith or) and )
!omment$ do not a*ect
code
-
7/23/2019 Lenguaje Usado en Arduino
10/52
!omment$
!omment$ can 'e any(here
!omment$ created (ith or ) and )
!omment$ do not a*ect code
+ou may not need comment$,'ut thin& a'out thecommunity-
-
7/23/2019 Lenguaje Usado en Arduino
11/52
"perator$
The eual$ $ign
/ i$ u$ed to a$$ign a value
// i$ u$ed to compare value$
-
7/23/2019 Lenguaje Usado en Arduino
12/52
"perator$
And 0 "r
00 i$ 1and2
33 i$ 1or2
-
7/23/2019 Lenguaje Usado en Arduino
13/52
4aria'le$
Ba$ic varia'le type$:
Boolean
5nteger
!haracter
-
7/23/2019 Lenguaje Usado en Arduino
14/52
6eclaring 4aria'le$
Boolean: booleanvariableName;
-
7/23/2019 Lenguaje Usado en Arduino
15/52
6eclaring 4aria'le$
Boolean: booleanvariableName;
5nteger: int variableName;
-
7/23/2019 Lenguaje Usado en Arduino
16/52
6eclaring 4aria'le$
Boolean: booleanvariableName;
5nteger: int variableName;
!haracter: charvariableName;
-
7/23/2019 Lenguaje Usado en Arduino
17/52
6eclaring 4aria'le$
Boolean: booleanvariableName;
5nteger: int variableName;
!haracter: char variableName;
String: stringName [ ];
-
7/23/2019 Lenguaje Usado en Arduino
18/52
A$$igning 4aria'le$
Boolean: variableName =true;
or variableName = false;
-
7/23/2019 Lenguaje Usado en Arduino
19/52
A$$igning 4aria'le$
Boolean: variableName =true;
or variableName = false;
5nteger: variableName =
32767;or variableName = -32768;
-
7/23/2019 Lenguaje Usado en Arduino
20/52
A$$igning 4aria'le$
Boolean: variableName = true;
or variableName = false;
5nteger: variableName = 32767;
or variableName = -32768;
!haracter: variableName = A;
or stringName = !"#ar$%un&;
-
7/23/2019 Lenguaje Usado en Arduino
21/52
4aria'le Scope7here you declare your varia'le$
matter$
-
7/23/2019 Lenguaje Usado en Arduino
22/52
Setup
voi' setu# ( ) * +
The $etup %unction come$ 'e%ore
the loop %unction and i$ nece$$ary%or all Arduino $&etche$
-
7/23/2019 Lenguaje Usado en Arduino
23/52
Setup
voi' setu# ( ) * +
The $etup header (ill never change,
everything el$e that occur$ in $etup
happen$ in$ide the curly 'rac&et$
-
7/23/2019 Lenguaje Usado en Arduino
24/52
Setupvoi' setu# ( )*
#in,o'e (3. /0101); +
"utput$ are declare in $etup, thi$ i$done 'y u$ing the pin#ode
%unctionThi$ particular e8ample declare$ digital pin 9 ; a$
an output, remem'er to u$e !APS
-
7/23/2019 Lenguaje Usado en Arduino
25/52
Setupvoi' setu# ( )
* "erialbegin;+
Serial communication al$o 'egin$
in $etupThi$ particular e8ample declare$ Serialcommunication at a 'aud rate o% >. #ore on
Serial later...
Setup 5nternal Pullup
-
7/23/2019 Lenguaje Usado en Arduino
26/52
Setup, 5nternal Pullup?e$i$tor$
voi' setu# ( )*'igital4rite (2. 55); +
+ou can al$o create internal pullup re$i$tor$ in$etup, to do $o digital7rite the pin @5G@
Thi$ ta&e$ the place o% the pullup re$i$tor$ currentlyon your circuit 'utton$
S t 5 t t
-
7/23/2019 Lenguaje Usado en Arduino
27/52
Setup, 5nterrupt$voi' setu# ( )*
attachnterru#t (interru#t.function. mo'e) +
+ou can de$ignate an interrupt%unction to Arduino pin$ 9
and ;
Thi$ i$ a (ay around the linearproce$$ing o% Arduino
S t 5 t t
-
7/23/2019 Lenguaje Usado en Arduino
28/52
Setup, 5nterrupt$voi' setu# ( )*
attachnterru#t (interru#t.function. mo'e) +Interrupt: the num'er o% the interrupt,> or , corre$ponding to Arduino pin$ 9
and ; re$pectively
Function: the %unction to call (hen theinterrupt occur$
Mode: deCne$ (hen the interrupt$hould 'e triggered
S t 5 t t
-
7/23/2019 Lenguaje Usado en Arduino
29/52
Setup, 5nterrupt$voi' setu# ( )*
attachnterru#t (interru#t.function. mo'e)+
/4(henever pin $tate i$ lo(
95AN:(henever pin change$ value"N(henever pin goe$ %rom lo( to
high
%AN (henever pin goe$ %rom lo(to high
6onDt %orget to !AP5TAL5E
-
7/23/2019 Lenguaje Usado en Arduino
30/52
If Statementsif ( this is true ) { do this; }
-
7/23/2019 Lenguaje Usado en Arduino
31/52
Ifif( this is true ) { do this; }
-
7/23/2019 Lenguaje Usado en Arduino
32/52
Conditionalif ( this is true ){ do this; }
-
7/23/2019 Lenguaje Usado en Arduino
33/52
Actionif ( this is true ) { do this; }
-
7/23/2019 Lenguaje Usado en Arduino
34/52
Elseelse { do this; }
-
7/23/2019 Lenguaje Usado en Arduino
35/52
Basic Repetition
loop
For
while
-
7/23/2019 Lenguaje Usado en Arduino
36/52
Basic Repetition
void loop ( ) { }
-
7/23/2019 Lenguaje Usado en Arduino
37/52
Basic Repetition
void loop ( ){ }
-
7/23/2019 Lenguaje Usado en Arduino
38/52
Basic Repetition
void loop ( ) { }
The void in the header is whatthe function will return or spit out!
when it happens" in this case it
returns nothin# so it is void
-
7/23/2019 Lenguaje Usado en Arduino
39/52
Basic Repetition
voidloop( ) { }
The loop in the header is what the
function is called" sometimes $ou ma%ethe name up" sometimes li%e loop! the
function alread$ has a name
-
7/23/2019 Lenguaje Usado en Arduino
40/52
Basic Repetition
voidloop ( ){ }
The ! in the header is where $ou
declare an$ varia&les that $ou arepassin# or sendin#! the function" the
loop function is never passed an$
varia&les
-
7/23/2019 Lenguaje Usado en Arduino
41/52
Basic Repetition
voidloop ( ) { }
-
7/23/2019 Lenguaje Usado en Arduino
42/52
Basic Repetition
for (int count = 0; count
-
7/23/2019 Lenguaje Usado en Arduino
43/52
Basic Repetition
for (int count = 0; count
-
7/23/2019 Lenguaje Usado en Arduino
44/52
Basic Repetition
for (int count = 0; count
-
7/23/2019 Lenguaje Usado en Arduino
45/52
Basic Repetition
for(int count = 0; count
-
7/23/2019 Lenguaje Usado en Arduino
46/52
Basic Repetition
for(int count = 0;count
-
7/23/2019 Lenguaje Usado en Arduino
47/52
Basic Repetition
for(int count = 0;count
-
7/23/2019 Lenguaje Usado en Arduino
48/52
Basic Repetition
for(int count = 0;count
-
7/23/2019 Lenguaje Usado en Arduino
49/52
Basic Repetition
while(count
-
7/23/2019 Lenguaje Usado en Arduino
50/52
Basic Repetition
while(count
-
7/23/2019 Lenguaje Usado en Arduino
51/52
Basic Repetition
while(count
-
7/23/2019 Lenguaje Usado en Arduino
52/52
Basic Repetition'r ma$&e(
while(digital&ead(button'in)==1)
{
//instead of changing a variable//you ust read a !in so the co!uter
//e%its when you !ress a button
//or a sensor is tri!!ed}