intro to arduino coding part 1

Upload: mrcanoehead1000

Post on 03-Jun-2018

240 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Intro to Arduino Coding Part 1

    1/13

    Introduction to Arduino Coding

  • 8/12/2019 Intro to Arduino Coding Part 1

    2/13

    )

    Code (rough definition)

    A series of instructions given to a

    computer to execute an action or series ofactions

  • 8/12/2019 Intro to Arduino Coding Part 1

    3/13

  • 8/12/2019 Intro to Arduino Coding Part 1

    4/13

    )

    Code (rough definition)

    A series of instructions given to a

    computer to execute an action or series ofactions

    The code i$$ %e run from the first $ine tothe $ast $ine in order

    It i$$ on$y do hat the code says for it to

    do

  • 8/12/2019 Intro to Arduino Coding Part 1

    5/13

    )

    Communicating To and &rom a

    Computer

    Commands: $ines that te$$ the computer hat

    to do

    'yntax rrors: the computer te$$s you hen

    you say something it does not understand

  • 8/12/2019 Intro to Arduino Coding Part 1

    6/13

    )

    &undamenta$s of rduino rogramming

    1 *ec$arations

    + ,oid setup

    - ,oid $oop

  • 8/12/2019 Intro to Arduino Coding Part 1

    7/13

    )

    this creates a varia%$e

    ca$$ed .$edin/ and

    assigns it the va$ue of1- for the pin that you

    have connected a ire

    to on the Arduino

  • 8/12/2019 Intro to Arduino Coding Part 1

    8/13

    int is used to dec$are ma0ing

    a varia%$e that is an integer

    (ho$e num%er that is

    negative or positive)

    this is the name of the integer

    "ou can ca$$ it anything youant except a num%er or

    something that has meaning

    a$ready ($i0e int) "ou shou$d

    name this something re$ated to

    the num%er it is storing In thiscase e ca$$ it $edin %ecause it

    is the pin $eading to the $ed

    this is the va$ue that

    $edin i$$ %e This va$ueis 1- since e are using

    this varia%$e to store the

    pin num%er that our $ed

    ire is connected to "ou must end $ines ith a

    semico$on (except $oopscomments if statements

    and functions)

  • 8/12/2019 Intro to Arduino Coding Part 1

    9/13

    )

    Another ay to

    rite this program

    removes the

    varia%$e ca$$ed$edin and you

    enter .1-/

    everyhere you

    had $edin Thisor0s %ut it is

    easier to use a

    varia%$e for the pin

    in case you ant tochange the pin

    num%er

  • 8/12/2019 Intro to Arduino Coding Part 1

    10/13

    )

    In the .setup/ function e $et the

    Arduino 0no hat things e are

    using 2&34 e use themThis is the type of

    function e are ma0ing

    A .void/ function does

    not return a va$ue

    This is the name of the

    function "ou a$ays shou$duse this first $ine in your

    Arduino programs

    5orma$$y in a function

    you put varia%$es that

    the function uses inhere 'ince e don6t

    have any it is empty ()"ou must have 7 8 cur$y

    %rac0ets that sho the

    start and end of the

    function Imagine this as

    the top and %ottom s$ices

    of %rea0 of your

    .function9sandich/pinode te$$s

    Arduino hat

    the pins do pinodeneeds + pieces of info

    The pin # and hat that

    pin i$$ %e used for

    pinode(pin # I5;T or

    3;T;T)

    Instead of a num%er e

    have a varia%$e here

    hich has a num%erva$ue assigned to it

    This is here e te$$ the

    computer ho this pin

    i$$ function The

    choices are I5;T or

    3;T;T

    "ou ;'T have thissemico$on

  • 8/12/2019 Intro to Arduino Coding Part 1

    11/13

    )

    The void $oop() function is here your main program $ies

    Li0e a$$ functionsyou

    must put 7 8 cur$y

    %rac0ets

    at the %eginning

    and endof your function

    sandichI?> @ oer 3nL3= @ oer 3ff

    *on6t forget your semico$ons